Skip to content

Commit

Permalink
Merge pull request #2564 from locustio/optimize-memory-usage-when-usi…
Browse files Browse the repository at this point in the history
…ng---processes

Optimize memory usage when using --processes
  • Loading branch information
cyberw committed Jan 25, 2024
2 parents 6936933 + 084d59a commit 13a76d6
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions locust/main.py
Expand Up @@ -4,6 +4,7 @@

import atexit
import errno
import gc
import inspect
import json
import logging
Expand Down Expand Up @@ -204,6 +205,9 @@ def is_valid_percentile(parameter):
"--master cannot be combined with --processes. Remove --master, as it is implicit as long as --worker is not set.\n"
)
sys.exit(1)
# Optimize copy-on-write-behavior to save some memory (aprx 26MB -> 15MB rss) in child processes
gc.collect() # avoid freezing garbage
gc.freeze() # move all objects to perm gen so ref counts dont get updated
for _ in range(options.processes):
child_pid = gevent.fork()
if child_pid:
Expand Down

0 comments on commit 13a76d6

Please sign in to comment.