processone / tsung

Tsung is a high-performance benchmark framework for various protocols including HTTP, XMPP, LDAP, etc.
http://www.process-one.net/en/tsung/
GNU General Public License v2.0
2.52k stars 404 forks source link

Memory issues with `match` on HTTP responses of SSE endpoints #370

Open pavelsolomin opened 4 years ago

pavelsolomin commented 4 years ago

Hello!

I use Tsung HTTP sessions to load test SSE endpoints of my Web application. At the moment, there seems to be no support for SSE sessions in Tsung, so, I do a "normal" HTTP GET to an SSE endpoint, and keep Tsung users stuck with open connections. So far, it was sufficient for my current needs, but I started getting Tsung memory issues with matchers.

Tsung version

$ $HOME/.asdf/bin/tsung -v
Tsung version 1.7.1_dev

Issue

When doing an HTTP GET to an endpoint with endless response like this:

                    <request subst="true">
                        <http url="%%_stream_url%%" method="GET" version="1.1">
                            <http_header name="Connection" value="keep-alive"/>
                            <http_header name="Content-Type" value="text/event-stream"/>
                        </http>
                    </request>

Tsung memory is stable

Screen Shot 2020-02-05 at 10 09 46 PM

But things change as soon as I add a matcher

                    <request subst="true">
                        <match do='restart' when='nomatch' name='03_get_stream_nomatch_200'>200</match>
                        <http url="%%_stream_url%%" method="GET" version="1.1">
                            <http_header name="Connection" value="keep-alive"/>
                            <http_header name="Content-Type" value="text/event-stream"/>
                        </http>
                    </request>

Tsung memory is always growing

Screen Shot 2020-02-05 at 10 11 29 PM

Expected behavior

When I do this:

<match do='restart' when='nomatch' name='03_get_stream_nomatch_200'>200</match>

I expect, given that status code arrives before the endless payload, that this matcher does not look for anything else besides the first line of an HTTP response.

I also expected Tsung to have some buffering of HTTP responses, such that it might deliver response data in chunks to the matcher, and not to keep loading the entire response forever. For example, curl http://localhost:4001/stream (example server code is attached) does not show such behavior of growing memory.

How to reproduce

I attached an archive with example SSE server and two Tsung scripts for reproducing this locally.

sse-example-server.tar.gz

I would also appreciate general suggestions regarding the approaches of using Tsung for my use case. I admit that using HTTP session is not ideal, there might be better ways to test SSE endpoints.

Thank you in advance.

fatso83 commented 4 years ago

I am also wondering a bit how to deal with SSE, as that is the main data transport channel for our SPA. If you ever publish more about your approach it would be great if you could add a pingback here (subscribing to this issue for now).