Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: StatsEntry.use_response_times_cache must be set to True #1531

Closed
max-rocket-internet opened this issue Aug 20, 2020 · 11 comments
Closed
Labels

Comments

@max-rocket-internet
Copy link
Contributor

I see this on every locust worker running 1.2:

$ locust --worker --locustfile=main.py
[2020-08-20 11:02:50,637] C02TD0F6GTDX/INFO/locust.main: Starting Locust 1.2
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
  File "/usr/local/lib/python3.8/site-packages/locust/stats.py", line 766, in stats_history
    'response_time_percentile_95': stats.total.get_current_response_time_percentile(0.95) or 0,
  File "/usr/local/lib/python3.8/site-packages/locust/stats.py", line 553, in get_current_response_time_percentile
    raise ValueError("StatsEntry.use_response_times_cache must be set to True if we should be able to calculate the _current_ response time percentile")
ValueError: StatsEntry.use_response_times_cache must be set to True if we should be able to calculate the _current_ response time percentile
2020-08-20T09:02:50Z <Greenlet at 0x10803f6a0: stats_history(<locust.runners.WorkerRunner object at 0x10806da60)> failed with ValueError

Tried with very basic locust file, same issue:

from locust import HttpUser, TaskSet, task, between

class LoadTestTask(TaskSet):
    def on_start(self):
        pass

    @task(3)
    def get_token(self):
        pass

class LoadTest(HttpUser):
    tasks = [LoadTestTask]
    wait_time = between(0.1, 1)

Any idea @cyberw or @vstepanov-lohika-tix?

@cyberw
Copy link
Collaborator

cyberw commented Aug 20, 2020

This line of code was added in #1516. @taojy123 , any ideas?

@taojy123
Copy link
Contributor

Let me see.
I am trying to reproduce the problem first.

@taojy123
Copy link
Contributor

taojy123 commented Aug 20, 2020

Sorry! In my development, I did not consider that the use_response_times_cache parameter of worker mode is False.
Solution to fix it:
Add two lines in stats_history function of locust/stats.py:

def stats_history(runner):
    """Save current stats info to history for charts of report."""
    while True:
        stats = runner.stats
        if not stats.total.use_response_times_cache:  # *** add this
            break  # *** add this
        r = {
            'time': datetime.datetime.now().strftime("%H:%M:%S"),
            'current_rps': stats.total.current_rps or 0,
            'current_fail_per_sec': stats.total.current_fail_per_sec or 0,
            'response_time_percentile_95': stats.total.get_current_response_time_percentile(0.95) or 0,
            'response_time_percentile_50': stats.total.get_current_response_time_percentile(0.5) or 0,
            'user_count': runner.user_count or 0,
        }
        stats.history.append(r)
        gevent.sleep(HISTORY_STATS_INTERVAL_SEC)

Should I make a new PR? @cyberw

taojy123 added a commit to taojy123/locust that referenced this issue Aug 20, 2020
@max-rocket-internet
Copy link
Contributor Author

Should I make a new PR?

Yes 🙂

@cyberw
Copy link
Collaborator

cyberw commented Aug 20, 2020

I made a PR myself :)

@cyberw cyberw closed this as completed in 7d366d0 Aug 20, 2020
cyberw added a commit that referenced this issue Aug 20, 2020
fix #1531 (ValueError: StatsEntry.use_response_times_cache must be set to True)
@cyberw
Copy link
Collaborator

cyberw commented Aug 20, 2020

Because this was in a release I made an emergency fix in my own PR & new release (1.2.1, on its way out now). @taojy123 , can you make a test case that excercises this scenario?

taojy123 added a commit to taojy123/locust that referenced this issue Aug 20, 2020
@taojy123
Copy link
Contributor

taojy123 commented Aug 20, 2020

ok
I made the test case in taojy123@2cd724c
The code like this:

    def test_stats_history(self):
        env1 = Environment(events=locust.events, catch_exceptions=False)
        runner1 = env1.create_master_runner("127.0.0.1", 5558)
        env2 = Environment(events=locust.events, catch_exceptions=False)
        runner2 = env2.create_worker_runner("127.0.0.1", 5558)
        greenlet1 = gevent.spawn(stats_history, runner1)
        greenlet2 = gevent.spawn(stats_history, runner2)
        gevent.sleep(1)
        hs1 = runner1.stats.history
        hs2 = runner2.stats.history
        gevent.kill(greenlet1)
        gevent.kill(greenlet2)
        self.assertEqual(1, len(hs1))
        self.assertEqual(0, len(hs2))

@cyberw
Copy link
Collaborator

cyberw commented Aug 20, 2020

Nice! Can you make a PR?

@taojy123
Copy link
Contributor

ok, I just woke up,I'll make a PR later.

@taojy123
Copy link
Contributor

@cyberw Hi~ I made the PR, see #1538

@Pryanga
Copy link

Pryanga commented Mar 22, 2022

Hi! I am able to reproduce the error when I run locust within python subprocess.Popen:

cmd = f'locust --host {base_host} -f locustfile-ws.py -u {max_user} -r {spawn_rate} -t {end_time} --audio ./sample/tanglin_short.wav \
        --server_type {server_type} --headless --csv {csv_prefix} --csv-full-history --master'
subprocess.Popen(cmd_.split())

cmd_line_worker = cmd_line.replace('--master', '--worker').replace(f'-t {end_time}', '')
    for i in range(0,4):
        subprocess.Popen(cmd_line_worker.split())

Error:

Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 94, in input_listener_func
    poller = get_poller()
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 88, in get_poller
    return UnixKeyPoller()
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 32, in __init__
    tty.setcbreak(self.stdin, termios.TCSANOW)
  File "/Users/uuu/.pyenv/versions/3.9.4/lib/python3.9/tty.py", line 36, in setcbreak
    tcsetattr(fd, when, mode)
termios.error: (5, 'Input/output error')
2022-03-23T08:28:13Z <Greenlet at 0x10fe80e10: input_listener_func> failed with error

[2022-03-23 16:28:13,555] uuu-MacBook-Pro.local/CRITICAL/locust.main: Unhandled exception in greenlet: <Greenlet at 0x10fe80e10: input_listener_func>
Traceback (most recent call last):
  File "src/gevent/greenlet.py", line 906, in gevent._gevent_cgreenlet.Greenlet.run
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 94, in input_listener_func
    poller = get_poller()
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 88, in get_poller
    return UnixKeyPoller()
  File "/Users/uuu/MyProjects/ins8-locust-loadtest/env/lib/python3.9/site-packages/locust/input_events.py", line 32, in __init__
    tty.setcbreak(self.stdin, termios.TCSANOW)
  File "/Users/uuu/.pyenv/versions/3.9.4/lib/python3.9/tty.py", line 36, in setcbreak
    tcsetattr(fd, when, mode)
termios.error: (5, 'Input/output error')
raise ValueError(
ValueError: StatsEntry.use_response_times_cache must be set to True if we should be able to calculate the _current_ response time percentile
2022-03-22T04:06:06Z <Greenlet at 0x1122debf0: <bound method StatsCSVFileWriter.stats_writer of <locust.stats.StatsCSVFileWriter object at 0x11231d7f0>>> failed with ValueError
...
 raise ValueError(
ValueError: StatsEntry.use_response_times_cache must be set to True if we should be able to calculate the _current_ response time percentile

Locust: 2.8.3
Mac BigSur

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants