Skip to content

Latest commit

History

History
64 lines (36 loc) 路 3.19 KB

testing-other-systems.rst

File metadata and controls

64 lines (36 loc) 路 3.19 KB

Testing other systems/protocols

Locust only comes with built-in support for HTTP/HTTPS but it can be extended to test almost any system. This is normally done by wrapping the protocol library and triggering a :pyrequest <locust.event.Events.request> event after each call has completed, to let Locust know what happened.

Note

It is important that the protocol libraries you use can be monkey-patched by gevent.

Almost any libraries that are pure Python (using the Python socket module or some other standard library function like subprocess) should work fine out of the box - but if they do their I/O calls in C, gevent will be unable to patch it. This will block the whole Locust/Python process (in practice limiting you to running a single User per worker process).

Some C libraries allow for other workarounds. For example, if you want to use psycopg2 to performance test PostgreSQL, you can use psycogreen. If you are willing to get your hands dirty, you may also be able to patch a library yourself, but that is beyond the scope of this documentation.

XML-RPC

Lets assume we have an XML-RPC server that we want to load test.

../examples/custom_xmlrpc_client/server.py

We can build a generic XML-RPC client, by wrapping :pyxmlrpc.client.ServerProxy.

../examples/custom_xmlrpc_client/xmlrpc_locustfile.py

gRPC

Lets assume we have a gRPC server that we want to load test:

../examples/grpc/hello_server.py

The generic GrpcUser base class sends events to Locust using an interceptor:

../examples/grpc/grpc_user.py

And a locustfile using the above would look like this:

../examples/grpc/locustfile.py

requests-based libraries/SDKs

If you want to use a library that uses a requests.Session object under the hood you will most likely be able to skip all the above complexity.

Some libraries allow you to pass a Session explicitly, like for example the SOAP client provided by Zeep. In that case, just pass it your HttpUser's :pyclient <locust.HttpUser.client>, and any requests made using the library will be logged in Locust.

Even if your library doesn't expose that in its interface, you may be able to get it working by overwriting some internally used Session. Here's an example of how to do that for the Archivist client.

../examples/sdk_session_patching/session_patch_locustfile.py

REST

See FastHttpUser <rest>

Other examples

See locust-plugins it has users for WebSocket/SocketIO, Kafka, Selenium/WebDriver, Playwright and more.