File tree 2 files changed +7
-11
lines changed
2 files changed +7
-11
lines changed Original file line number Diff line number Diff line change @@ -137,15 +137,13 @@ the messages will simply be handled by the runner that sends them.
137
137
Using the default options while registering a message handler will run the listener function
138
138
in a **blocking ** way, resulting in the heartbeat and other messages being delayed for the amount
139
139
of the execution.
140
- If it is known that the listener function will handle time-intensive tasks, it is possible to register the
141
- function as **concurrent ** (as a separate greenlet).
140
+ If you think that your message handler will need to run for more than a second then you can register it
141
+ as **concurrent **. Locust will then make it run in its own greenlet. Note that these greenlets will never
142
+ be join():ed.
142
143
143
144
.. code-block ::
144
145
environment.runner.register_message('test_users', setup_test_users, concurrent=True)
145
146
146
- Please use this feature with care, as otherwise it could result in greenlets running and influencing
147
- the running loadtest.
148
-
149
147
For more details, see the `complete example <https://github.com/locustio/locust/tree/master/examples/custom_messages.py >`_.
150
148
151
149
Original file line number Diff line number Diff line change 9
9
def setup_test_users (environment , msg , ** kwargs ):
10
10
# Fired when the worker receives a message of type 'test_users'
11
11
usernames .extend (map (lambda u : u ["name" ], msg .data ))
12
- # Even though "acknowledge_concurrent_users" was sent first, "acknowledge_users"
13
- # will print its statement first, as "acknowledge_concurrent_users" was registered
14
- # running concurrently, and therefore not blocking other messages.
15
- environment .runner .send_message ("concurrent_message" , "This is a non blocking message" )
16
12
environment .runner .send_message ("acknowledge_users" , f"Thanks for the { len (msg .data )} users!" )
13
+ environment .runner .send_message ("concurrent_message" , "Message to concurrent handler" )
17
14
18
15
19
16
def on_acknowledge (msg , ** kwargs ):
@@ -22,8 +19,9 @@ def on_acknowledge(msg, **kwargs):
22
19
23
20
24
21
def on_concurrent_message (msg , ** kwargs ):
25
- gevent .sleep (10 )
26
- print (msg .data )
22
+ print (f"concurrent_message received with data: '{ msg .data } '" )
23
+ gevent .sleep (10 ) # if this handler was run with concurrent=False it would halt the message handling loop in locust
24
+ print ("finished processing concurrent_message" )
27
25
28
26
29
27
@events .init .add_listener
You can’t perform that action at this time.
0 commit comments