Python script for performance testing of server
Question: I dont want to use any testing tool.. I am writing python script which hits
rest api to server... I want to hit 500/any_number_of hits of login/any api to
server at a same time so that I can check performance of server.

    
    
        def login():    
               api = "http://0.0.0.0/api/method/login"
               params = {"usr":"a@a.com","pwd":"password"}
               reponse = requests.post(api,params=params)
    
        def main():
               for i in range(2):
                    for j in range(5):
                            t1 = Thread(target=login(), args=(j,))
                            t2 = Thread(target=get_profile(), args=(j,))
                    t1.start()
                    t2.start()
         main()
    

will this code work ?? please suggest me how to do it...


Answer: Use a couroutine module like gevent or asyncio. You can have many coroutines,
but you will be limited in the number of threads. This limitation comes from
both the number of threads the OS will allow your process to have, and the
fact that threads incur a much greater performance hit (each thread needs its
own stack + cost of context switching).

Here's a way to do it with gevent:

    
    
    from gevent import monkey monkey.patch_all()
    import urllib2
    from gevent.pool import Pool
    
    def download(url):
        return urllib2.urlopen(url).read()
    
    if __name__ == '__main__':
        urls = ['http://your_url'] * 100
        pool = Pool(20)
        print pool.map(download, urls)
    

