question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

network_timeout is not respected

See original GitHub issue

I’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:closed
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
rokcarlcommented, Apr 6, 2020

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!

0reactions
cyberwcommented, Apr 6, 2020

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:

from locust import task
class WebsiteUser(FastHttpLocust):
    @task 
    def index(self):
        self.client.get("/slow")
    wait_time = constant_pacing(1.0)
    network_timeout = 1.0
    connection_timeout = 1.0
Read more comments on GitHub >

github_iconTop Results From Across the Web

SNOW-499494: network timeout not respected during ... - GitHub
During yesterday's outage on snowflake, our request setting (was set to 20 seconds) was not respected and all queries timed out after 50...
Read more >
Windows Server 2019 - Windows socket receive timeout does ...
Issue: Socket receive timeout is 1000 times faster than the value was defined in the timeval struct (in WinSock2.h). The issue does not...
Read more >
Timeout for GQL query not exceeding 10s - Retool Forum
... manual timeout value to, Retool fails with a network timeout error. ... Timeout after (ms) ) not being respected when the query...
Read more >
how to check HikariCP connection pooling is working or not in ...
First, configuration is no consistent since maximum < minimumIdle. ... is known to be broken with respect to network timeout support.
Read more >
PowerDNS Recursor Settings
In contrast to regular forwarding, the rule that delegations of the forwarded subzones are respected is not active. This is because we rely...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found