Exemplo n.º 1
0
def CreateRequesters(num_senders, max_qps, url, logger_obj, google_ids=None,
                     seconds=0, requests=0, interval=0):
  """Creates num_senders threads, and a sender.HTTPSender object for each.

  Args:
    num_senders: The number of sender threads to create.
    max_qps: Max overall qps.
    url: The URL to which senders will send requests.
    logger_obj: A log.Logger object.
    google_ids: A list of Google user IDs or None to randomly generate user ids.
    seconds: The number of seconds to continue sending requests.
    requests: The number of requests to send.
    interval: The number of seconds to wait between thread creation.

  Returns:
    A list of Requester objects.
  """
  seconds = seconds or 0
  requests = requests or 0
  # Create at most max_qps/10 threads, giving each thread at least 10 QPS.
  num_senders = min(num_senders, max_qps / 10)
  num_senders = max(num_senders, 1)  # Avoid setting num_senders to 0.
  send_rate_per_sender = num_senders / float(max_qps)
  requests_per_sender = requests / num_senders
  requesters = []
  for i in xrange(num_senders):
    generator_obj = generator.RandomBidGenerator(google_ids)
    sender_obj = sender.HTTPSender(url)
    requester = Requester(generator_obj, logger_obj, sender_obj,
                          send_rate_per_sender, seconds, requests_per_sender)
    requester.name = 'requester-thread-%d' % i
    requesters.append(requester)
    if interval:
      time.sleep(interval)
  return requesters
Exemplo n.º 2
0
def CreateRequesters(num_senders,
                     max_qps,
                     url,
                     logger_obj,
                     tanx_ids=None,
                     seconds=0,
                     requests=0,
                     interval=0,
                     mobile_rate=0,
                     mobile_device_ids=None,
                     video_rate=0,
                     video_ad_type=0):
    """创建num_senders线程,并为每个创建sender.HTTPSender对象

  Args:
   num_senders:发件人线程创建
   max_qps:最大的整体QPS
   url:发件人将请求发送到的URL
   logger_obj:log.Logger对象
   tanx_ids:Tanx用户ID或没有随机生成的用户ID列表
   seconds:继续发送请求的秒数。
   requests:请求发送。
   interval:秒之间等待的线程创建的数量。
   mobile_rate: 按照多少比例产生含有mobile消息的bid请求
   mobile_device_ids: mobile消息内部的device_id列表
   video_rate:  产生视频广告bid请求的比例
   video_ad_type: 视频广告的类型, 0表示非线性广告, 1表示线性广告

  Returns:
    A list of Requester objects.
  """
    seconds = seconds or 0
    requests = requests or 0
    # Create at most max_qps/10 threads, giving each thread at least 10 QPS.
    num_senders = min(num_senders, max_qps / 10)
    num_senders = max(num_senders, 1)  # Avoid setting num_senders to 0.
    send_rate_per_sender = num_senders / float(max_qps)
    requests_per_sender = requests / num_senders
    requesters = []
    for i in xrange(num_senders):
        generator_obj = generator.RandomBidGenerator(tanx_ids, mobile_rate,
                                                     mobile_device_ids,
                                                     video_rate, video_ad_type)
        sender_obj = sender.HTTPSender(url)
        requester = Requester(generator_obj, logger_obj, sender_obj,
                              send_rate_per_sender, seconds,
                              requests_per_sender)
        requester.name = 'requester-thread-%d' % i
        requesters.append(requester)
        if interval:
            time.sleep(interval)
    return requesters
Exemplo n.º 3
0
def CreateRequesters(num_senders,
                     max_qps,
                     url,
                     logger_obj,
                     seconds=0,
                     requests=0,
                     mobile_proportion=0):
    """
    @note: 创建 线程, 每个线程创建sender.HTTPSender和feeder.HTTPSender对象
    @params:
    num_senders: 创建的线程数 
    max_qps: 最大的qps 
    url: 竞价的rtb_url 
    logger_obj: 日志对象 
    seconds: 每个持续发送的时间 
    requests: 每个发送的请求个数
    mobile_proportion: 移动流量比例(0-100)
    @return: 返回创建的所有线程
    """
    seconds = seconds or 0
    requests = requests or 0
    # Create at most max_qps/10 threads, giving each thread at least 10 QPS.
    num_senders = min(num_senders, max_qps / 10)
    num_senders = max(num_senders, 1)  # Avoid setting num_senders to 0.
    send_rate_per_sender = num_senders / float(max_qps)
    requests_per_sender = requests / num_senders
    requesters = []
    for i in xrange(num_senders):
        generator_obj = generator.BidGeneratorManager(mobile_proportion)
        sender_obj = sender.HTTPSender(url)
        requester = Requester(generator_obj, logger_obj, sender_obj,
                              send_rate_per_sender, seconds,
                              requests_per_sender)
        requester.name = 'requester-thread-%d' % i
        requesters.append(requester)
    return requesters
Exemplo n.º 4
0
 def testInitWithPathAndPort(self):
   """Tests with a URL with a path and port."""
   self.sender = sender.HTTPSender('http://google.com:1234/mypath/hello')
   self.assertEqual('google.com', self.sender._host)
   self.assertEqual('/mypath/hello', self.sender._path)
   self.assertEqual('1234', self.sender._port)
Exemplo n.º 5
0
 def testInitWithPathWithoutPort(self):
   """Tests with a URL with a path, and no port."""
   self.sender = sender.HTTPSender('http://google.com/mypath/hello')
   self.assertEqual('google.com', self.sender._host)
   self.assertEqual('/mypath/hello', self.sender._path)
   self.assertEqual('80', self.sender._port)
Exemplo n.º 6
0
 def testInitWithPortWithoutPath(self):
   """Tests with a URL with a port, and no path."""
   self.sender = sender.HTTPSender('http://google.com:8080')
   self.assertEqual('google.com', self.sender._host)
   self.assertEqual('/', self.sender._path)
   self.assertEqual('8080', self.sender._port)
Exemplo n.º 7
0
 def testInitWithoutPortOrPathWithPathDelimiter(self):
   """Tests with a URL with no port or path, but with a path delimiter."""
   self.sender = sender.HTTPSender('http://google.com/')
   self.assertEqual('google.com', self.sender._host)
   self.assertEqual('/', self.sender._path)
   self.assertEqual('80', self.sender._port)
Exemplo n.º 8
0
 def testInitWithoutPortOrPath(self):
   """Tests initializing with a URL with no port or path."""
   self.sender = sender.HTTPSender('http://google.com')
   self.assertEqual('google.com', self.sender._host)
   self.assertEqual('/', self.sender._path)
   self.assertEqual('80', self.sender._port)