network_timeout is not respected
See original GitHub issueI’m using network_timeout = 1.0
on a FastHttpLocust
subclass, but the slow pages still succeed. I would expect that after 1.0s, the request would stop and another one would start. Additionally, I would expect the page load to count as an error. What I’m seeing though is that Locust is waiting for the page to load and counting it as a success.
I know there’s a test in the codebase for this, but it only checks if there was an error in the slow page, but this could be due to other things.
Code for my Flask test web server `app.py`
import random
import time
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
time.sleep(random.random() * 0.9)
return 'Hello, World!'
@app.route('/slow')
def slow():
sleep = 3 + random.random()
time.sleep(sleep)
return f'Took me {sleep} s.'
@app.route('/400')
def bad_request():
return 'Bad Request for your data', 400
My `locust.py` file:
from locust import TaskSet
from locust.contrib.fasthttp import FastHttpLocust
from locust.wait_time import constant_pacing
def index(l):
l.client.get("/slow")
class UserBehavior(TaskSet):
tasks = {index: 1}
class WebsiteUser(FastHttpLocust):
task_set = UserBehavior
wait_time = constant_pacing(1.0)
network_timeout = 1.0
connection_timeout = 1.0
I run the web server with flask run --reload
(need pip install flask
) and run the locust without the GUI using locust -f locust.py --no-web -c 10 -r 10 -t 10s --host http://localhost:5000
.
Here are the results
locust -f locust.py --no-web -c 10 -r 10 -t 10s --host http://localhost:5000
[2020-04-03 12:07:19,301] Roks-MacBook-Pro-2.local/INFO/locust.runners: Hatching and swarming 10 users at the rate 10 users/s (0 users already running)...
[2020-04-03 12:07:20,229] Roks-MacBook-Pro-2.local/INFO/locust.runners: All locusts hatched: WebsiteUser: 10 (0 already running)
[2020-04-03 12:07:20,306] Roks-MacBook-Pro-2.local/INFO/locust.main: Run time limit set to 10 seconds
[2020-04-03 12:07:20,306] Roks-MacBook-Pro-2.local/INFO/locust.main: Starting Locust 0.14.5
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 0 0(0.00%) 0 0 0 | 0 0.00 0.00
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 0 0(0.00%) 0 0 0 | 0 0.00 0.00
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET /slow 10 0(0.00%) 3574 3100 4001 | 3400 0.00 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 10 0(0.00%) 3574 3100 4001 | 3400 0.00 0.00
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET /slow 10 0(0.00%) 3574 3100 4001 | 3400 0.00 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 10 0(0.00%) 3574 3100 4001 | 3400 0.00 0.00
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET /slow 20 0(0.00%) 3516 3095 4001 | 3400 1.43 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 20 0(0.00%) 3516 3095 4001 | 3400 1.43 0.00
[2020-04-03 12:07:30,307] Roks-MacBook-Pro-2.local/INFO/locust.main: Time limit reached. Stopping Locust.
[2020-04-03 12:07:30,309] Roks-MacBook-Pro-2.local/INFO/locust.main: Shutting down (exit code 0), bye.
[2020-04-03 12:07:30,309] Roks-MacBook-Pro-2.local/INFO/locust.main: Cleaning up runner...
[2020-04-03 12:07:30,309] Roks-MacBook-Pro-2.local/INFO/locust.main: Running teardowns...
Name # reqs # fails Avg Min Max | Median req/s failures/s
--------------------------------------------------------------------------------------------------------------------------------------------
GET /slow 21 0(0.00%) 3502 3095 4001 | 3400 1.91 0.00
--------------------------------------------------------------------------------------------------------------------------------------------
Aggregated 21 0(0.00%) 3502 3095 4001 | 3400 1.91 0.00
Percentage of the requests completed within given times
Type Name # reqs 50% 66% 75% 80% 90% 95% 98% 99% 99.9% 99.99% 100%
------------------------------------------------------------------------------------------------------------------------------------------------------
GET /slow 21 3400 3600 3700 3800 4000 4000 4000 4000 4000 4000 4000
------------------------------------------------------------------------------------------------------------------------------------------------------
None Aggregated 21 3400 3600 3700 3800 4000 4000 4000 4000 4000 4000 4000
You can see that all the requests were successful, but all of them should have failed and there should have been more requests, as each one should fail after 1.0 s.
Environment:
- OS: Mac OS
- Python version: Python 3.7.1
- Locust version: 0.14.5
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (2 by maintainers)
Top GitHub Comments
Yes, this works and the timeout works as well, I ran it against my mock website with a timeout of
0.5 + random.random()
(so between 0.5 and 1.5) and half of the requests were successful and half were a failure.Thank you!
Hmm. Not sure what is the problem (it could definitely be related to 1.0 changes), but if you use this syntax it should work: