Challenge: How to send > 1000 HTTP requests in one second with Python

后端 未结 1 1636
情书的邮戳
情书的邮戳 2021-01-14 05:47

Consider the following case: There is a slow server which use about 200ms to handle a request (no including the network transfer time). And now, we need to

相关标签:
1条回答
  • 2021-01-14 06:35

    I know this is an old post but someone might still need this.

    If you want to do load testing but want to use python then you should use a tool like locust: http://locust.io/

    Here is my solution which resulted in 10,000 requests in 10 seconds:

    Needed Package: sudo pip install grequests

    Code:

    import grequests
    import time
    
    start_time = time.time()
    # Create a 10000 requests
    urls = ['http://www.google.co.il']*10000
    rs = (grequests.head(u) for u in urls)
    
    # Send them.
    grequests.map(rs)
    
    print time.time() - start_time # Result was: 9.66666889191
    
    0 讨论(0)
提交回复
热议问题