Support for custom clients
See original GitHub issueSupport for custom clients
This is a proposal for how we could implement official support for custom request/response based clients.
Reasoning
The reason we would like to do this is both to officially support testing of other request/response based systems than HTTP, but also to provide the ability to swap out the current requests based (http://docs.python-requests.org/) HTTP client, in favor for some other HTTP client. For example, if you’re running extremely large load tests where you’re doing tenths of thousands of requests per second, the overhead python-requests comes with can actually have a quite large impact.
Proposal
I’ve given this some thought, but it’s most likely not optimal. However it’s good to start somewhere, so you can see it as a starting point for a discussion on how to best implement this 😃.
One would specify the client class on the locust class(es) like this:
class User(Locust):
client_class = ThriftClient
...
We would modify the Locust base class to something like this (which will allow one to either just set client_class on the Locust class, or override the get_client() method):
class Locust(...):
...
def init(self, ...):
self.client = self.get_client()
def get_client(self):
return self.client_class(self)
...
The client classes should then expect to get an instance of a Locust subclass to their init method (which can be used to read Locust.host etc.), and the client is also responsible for fire:ing request_success and request_failure events when it does requests (which of course should be clearly documented).
Finally, we should also change the HTTP specific labels that we have in the UI (I think it might only be “Method”, which we could rename to “Type”).
So, what do you think? ping @cgbystrom @Jahaja
Issue Analytics
- State:
- Created 10 years ago
- Comments:9 (6 by maintainers)
Top GitHub Comments
@heyman / @cgbystrom :Could you please give me an example or explanation on how to write locust load test with custom client ( WebSocket Server in my case ). I saw the explanation given in locust documentation but I dint get how exactly the functions
__getattr__
anddef wrapper(*args, **kwargs):
which hooks locust events are getting triggered via locust.Fixed!