def init_test(self): ready = self.config.get('endpoint').replace('status', 'ready') self.logger.debug(ready) while True: try: self.logger.info('Trying Hooyu...') r = requests.get(ready, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from ready endpoint') break except Exception: self.logger.error('Hooyu isnt ready yet') time.sleep(1) endpoint = self.config.get('endpoint') self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( endpoint, cookiejarfile=f'/assets/cookies-{self.config["cluster"]}.txt', method='GET', user_agent='reqgen', auth_type='basic', ) self.args = { 'req': self.req, 'adapter': self.adapter, }
def init_test(self): status = f'{self.config.get("endpoint")}/status' self.logger.debug(status) while True: try: self.logger.info('Trying b1-frontend...') r = requests.get(status, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from status endpoint') break except Exception: self.logger.error('b1-frontend isnt ready yet') time.sleep(1) self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( self.config['endpoint'], method='GET', user_agent='reqgen', ) self.args = { 'req': self.req, 'adapter': self.adapter, }
def init_test(self): self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( self.config['endpoint'], method='GET', user_agent='reqgen', ) self.args = { 'req': self.req, 'adapter': self.adapter, }
def init_test(self): ready = self.config.get('endpoint').replace('/graphql', '/ready') self.logger.debug(ready) while True: try: self.logger.info('Trying Public GraphQL API...') r = requests.get(ready, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from ready endpoint') break except Exception: self.logger.error('Public API isnt ready yet') time.sleep(1) endpoint = self.config.get('endpoint') self.data = { "operationName": "Categories", "variables": {}, "query": "query Categories {\n categories {\n category_id\n name\n __typename\n }\n}\n" } self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( endpoint, params={}, data=self.data, cookiejarfile=None, auth=None, method='POST', user_agent='reqgen', auth_type='basic', headers={'Content-Type': 'application/json'}, files=[], # this will get filled by the workers insecure=False, nokeepalive=False, http2=False) self.args = { 'req': self.req, 'query': self.data, 'adapter': self.adapter, }
def init_test(self): ready = self.config.get('endpoint').replace('files', 'ready') self.logger.debug(ready) while True: try: self.logger.info('Trying CAS...') r = requests.get(ready, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from ready endpoint') break except Exception: self.logger.error('CAS isnt ready yet') time.sleep(1) endpoint = self.config.get('endpoint') cookiejarfile = f'/assets/cookies-{self.config["cluster"]}.txt' if self.name.startswith('generator-1-'): image_hash = self.upload_file(endpoint, cookiejarfile) else: image_hash = '20eecb396b7734682a42cceb9a5ab21eb7711ed84cfdc64652c5942abe854bc7' self.logger.debug(image_hash) self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder(os.path.join( endpoint, image_hash), params={}, data=None, cookiejarfile=cookiejarfile, auth=None, method='GET', user_agent='reqgen', auth_type='basic', headers={}, files=[], insecure=False, nokeepalive=False, http2=False) self.args = { 'req': self.req, 'adapter': self.adapter, }
def init_test(self): ready = self.config.get('endpoint').replace('/blockchain/transact', '/ready') self.logger.debug(ready) while True: try: self.logger.info('Trying Private Signing Service API...') r = requests.get(ready, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from ready endpoint') break except Exception: self.logger.error('Private Signing API isnt ready yet') time.sleep(1) endpoint = self.config.get('endpoint') jwt = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwicm9sZSI6ImludGVybmFsX3NlcnZpY2UiLCJzZXJ2aWNlTmFtZSI6ImIxLWFwaS1ncmFwaHFsLXByaXZhdGUtaWRlbnRpdHkiLCJpYXQiOjE1MTYyMzkwMjJ9.C8SqnTnkTaa6wSGFC1mWX_DCTG41rO_ifRu4MnU_Pls' self.data = {} self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( endpoint, params={}, data=self.data, cookiejarfile=None, auth=None, method='POST', user_agent='reqgen', auth_type='basic', headers={ 'Content-Type': 'application/json', 'Authorization': f'Bearer {jwt}' }, files=[], # this will get filled by the workers insecure=False, nokeepalive=False, http2=False) self.args = { 'req': self.req, 'query': self.data, 'adapter': self.adapter, }
def init_test(self): ready = self.config.get('endpoint').replace('files', 'ready') self.logger.debug(ready) while True: try: self.logger.info('Trying CAS...') r = requests.get(ready, timeout=5) if r.status_code == 200: self.logger.info('Got 200 from ready endpoint') break except Exception: self.logger.error('CAS isnt ready yet') time.sleep(1) endpoint = self.config.get('endpoint') self.rps = int(self.config['rps']) self.duration = int(self.config['duration']) self.threads = int(self.config['threads']) self.adapter = requests.adapters.HTTPAdapter( pool_connections=self.threads, pool_maxsize=self.threads * 10) self.req = request_builder.RequestBuilder( endpoint, params={}, data=None, cookiejarfile=f'/assets/cookies-{self.config["cluster"]}.txt', auth=None, method='POST', user_agent='reqgen', auth_type='basic', headers={}, files=[], # this will get filled by the workers insecure=False, nokeepalive=False, http2=False) self.args = { 'req': self.req, 'payload_size': self.config['payload_size'], 'file_path': '/assets/', 'adapter': self.adapter, }
return request_generator.Result(filename, 200, 0) if __name__ == '__main__': rps = 120 duration = 10 # An API calling test req = request_builder.RequestBuilder( 'https://jsonplaceholder.typicode.com/todos/1', params={}, data=None, cookiejarfile=None, auth=None, method='GET', user_agent='reqgen', auth_type='basic', headers={}, files=[], insecure=False, nokeepalive=False, http2=False) args = {'req': req} print(f'api_call: {duration} sec @ {rps} rps ({rps*duration} requests)') reqgen = request_generator.RequestGenerator(rps, duration, api_call, args) start = time.perf_counter() num_requests = reqgen.run(output_file='output_api.log') elapsed = time.perf_counter() - start print(f'num_requests: {num_requests} ({elapsed} sec)')