we are considering using K6 to load test one of our backend applications. The truth is that K6 looks very good and we like a lot what we are reading. We just have a question about how to test one of our scenarios.
Some of the tasks that our application does take a lot of time (between 5-10 minutes). The client sends a request, an identifier is returned, the task starts processing and when the task is finished the service does a callback to send the result.
Can K6 test the time between sending the request and receiving the response?
I’m confused with your usage of “callback” here. According to your diagram, the service makes a call back to the client. Are you using a bidirectional protocol like WebSockets? k6 doesn’t have good support yet for mechanisms like HTTP long polling or Server Sent Events, which you would typically use to implement callbacks.
So I’m assuming your client is making HTTP requests to the status endpoint at a specific interval using the task identifier to check the progress, correct? This isn’t really a callback, though, just regular polling.
If so, you can keep track of the time it takes between when the client makes the initial request, and when it receives the response that the task is finished, using Date.now(), and then add the result to a custom metric. You can see a similar solution here.
thanks for the reply and apologies for not being clear enough.
The protocol used to communicate the client and the application is HTTP, we cannot use WebSockets because of the limitations of one of the clients.
I will try to describe the steps better:
1.- The client makes an HTTP request with the necessary information to perform the task and the URL where to receive the callback with the response.
2.- The application returns a GUID to identify the requested task.
3.- This initial request is finished.
4.- The application executes the task.
5.- When the task is finished the application makes another HTTP request to the URL indicated in the initial request. In this request it sends the result of the requested task.
I hope that now my problem is clearer. If anyone would like me to specify any more points, I will be happy to do so.
I see. So the client in the first request sends the URL that the server should notify once the task is done. This sounds like a webhook.
What is serving this webhook endpoint? Is there a way for the client (k6) to monitor when the webhook is triggered?
You would need to implement a mechanism for k6 to check if a request was made to the webhook, and k6 would have to poll this service at some regular interval.
There are more experimental ways to approach this that wouldn’t involve polling, but would require writing a k6 extension in Go. For example, you could have a JS extension that starts a web server, and exposes a minimal JS API. Then you pass one of its endpoint URLs to the backend server to use as a webhook, and call a JS method from the extension that would block until a request is made to the webhook. This wouldn’t be very difficult to implement, but does require some Go knowledge.
So you would either need to have support for this on the backend, or implement a mechanism so that k6 can be notified when the webhook is triggered. Either solution goes beyond what we can help you with on this forum, though, but feel free to ask any other questions.
Neither I nor anyone else in the company has experience with Go, so the option of developing an extension in Go seems complicated.
Pulling the client to see if it has received the call to the webhook is complicated because we are not free to touch the client’s code and also if the process is initiated by K6 the client will not know anything about the request.
Another option that has occurred to us is to place a third application between K6 and the application that makes the asynchronous calls synchronous.