Search code examples
next.jsjmeterstress-testing

Perform a jmeter stress test on nextjs app exhausting ports


Im totally newbie in stress testing, just to mention.

A little bit info to understand project, not the question itself: I have webapp in nextjs14. Got requirement from a client to be able to support 400-500 simultaneous users connected and working with it. Also app designed to be real-time. All data on same page for every user must be updated for every user automatically. I use websockets for this part, to send a signal to connected clients to fetch fresh data. So, in worst scenario, if all users connected to the same page, server must complete 500 requests simultaneously.

So, i set a jmeter test to simulate user's first login, fetching necessary data.

Test look like this:

I set test to 400 users, ramp-up to 10sec. And test in 2 ways. One time loop and then 50 loops.

  1. Load login page and get csrf token.
  2. POST credentials (i have http cookie manager)
  3. Load page with some data
  4. GET data from api (simulating JS "loaded" with fetching all required data on this page)

Quiestions part SHORTLY:

If i run test once, everything is ok. If i run loop for 50 times, then i have problem with exhausted ports, no matter if i check or uncheck keep-alive checkbox in JMeter. In a few seconds of test in the end i reach limit of 65535 ports. Netstat shows that mostly all of them in TIME_WAIT state. And server start returning errors after i hit limit.

A little bit more description:

First i was trying do this on my local pc on win10.

I got very poor performance, nextjs server was unable to handle this amount of requests. So i set up nginx and set round-robin for 5 nextjs servers. That fix the issue with performance, but after 1000 samples i get error responses.

Figured out that win10 have a low limit of ports can be used. So i set up linux on a virual machine and did same test. Performance now is much better, but i reach limit of ports of 65535.

Never did apps that can be under heavy load, so im a bit lost. Im pretty sure i can fix poor performance for code, but with limits of system iteself i need a hints please.

What i probably did wrong and what i can do to bypass this issues.

I cant even say if this jmeter test is represet something real, or behaviour in browser will be different. I thought to test with selenium plugin, but 400-500 browsers nearly impossible for me to run for test.

Any info and links that can be helpful to read is very appreciated! Thanks in advance.


Solution

  • upstream http_backend {
        server 127.0.0.1:8080;
    
        keepalive 16;
    }
    
    server {
        ...
    
        location /http/ {
            proxy_pass http://http_backend;
            proxy_http_version 1.1;
            proxy_set_header Connection "";
            ...
        }
    }
    

    proxy_http_version 1.1 solved my problem. now TIME_WAIT ports are very low for amout of connections JMeter creates, most of the connections now have status ESTABLISHED.

    NGINX Keep-Alive settings options