Cisplatin
Cisplatin

Reputation: 2998

Load testing with Python's requests?

I want to use the Python requests library to send many HTTP requests at the same time, as I'm load testing my server. Is there an easy way to go about this?

EDIT: For clarification, I know how to send a request with requests. What I don't know is how to send another request before awaiting the response.

Upvotes: 2

Views: 5814

Answers (1)

Cisplatin
Cisplatin

Reputation: 2998

For future reference in case anyone else ends up having the same issue: I ended up using the Threading library, and simply creating a few hundred threads, each of these sending an HTTP request.

It was much simpler than it appeared. A good example that made it fairly clear was here. Specifically, this code was a great help:

import threading

def worker(num):
    """thread worker function"""
    print 'Worker: %s' % num
    return

threads = []
for i in range(5):
    t = threading.Thread(target=worker, args=(i,))
    threads.append(t)
    t.start()

Upvotes: 5

Related Questions