I create requests
POST-requests like this, where I specify timeout threshold:
response = requests.post(url, data=post_fields, timeout=timeout)
However, to determine a "good" threshold value, I would like to benchmark the server response time in advance.
How do I compute the minimum and maximum response times for the server?
To measure server response time, you can use a few potential metrics. Most often, admins measure server response time with a term called Time to First Byte (TTFB), which represents the time it takes in milliseconds for a browser to receive the first byte of the response from a server.
It will wait until the response arrives before the rest of your program will execute. If you want to be able to do other things, you will probably want to look at the asyncio or multiprocessing modules. Chad S. Chad S.
By default, requests do not have a timeout unless you explicitly specify one.
The Response
object returned by requests.post()
(and requests.get()
etc.) has a property called elapsed
, which provides the time delta between the Request
was sent and the Response
was received. To get the delta in seconds, use the total_seconds()
method:
response = requests.post(url, data=post_fields, timeout=timeout) print(response.elapsed.total_seconds())
Note that requests.post()
is a synchronous operation, which means that it blocks until the Response
is received.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With