JMeter-WebSocketSampler icon indicating copy to clipboard operation
JMeter-WebSocketSampler copied to clipboard

Large number of threads

Open bpapez opened this issue 10 years ago • 5 comments

I am using your jmeter plugin (version-1.0.2) and test with 320 concurrent users in a thread group using a WebSocket sampler within a long running loop, with setting the username as "Connection Id" and enabling "Streaming connection". I'm having troubles (OutOfMemoryError: unable to create new native thread) and wondered why such a high number of threads:

From a thread dump I see that there are currently: 2480 threads named WebSocketClient@#-#-selector-WebSocketClientSelectorManager@#/' 307 threads named WebSocketClient@#-scheduler 539 threads named WebSocketClient@#-#

The huge number of threads seem to come from each thread creating a new WebSocketClient, which has a thread pool of minimal 8 threads.

As the number of concurrent editors can go way higher than the 320 we tested today, we would need to somehow reduce the number of threads created via the WebSocketSampler. I see that the WebSocketClient constructor allows to also set an Executor object as 2nd parameter. I would therefore suggest to add a:

private static ExecutorService executor = Executors.newCachedThreadPool(); 

and change the getConnectionSocket() method to look like this:

    private ServiceSocket getConnectionSocket() throws URISyntaxException, Exception {
        URI uri = getUri();

        String connectionId = getThreadName() + getConnectionId();

        if (isStreamingConnection() && connectionList.containsKey(connectionId)) {
            ServiceSocket socket = connectionList.get(connectionId);
            socket.initialize();
            return socket;
        }

        //Create WebSocket client
        SslContextFactory sslContexFactory = new SslContextFactory();
        sslContexFactory.setTrustAll(isIgnoreSslErrors());
        WebSocketClient webSocketClient = new WebSocketClient(sslContexFactory, executor);

        ServiceSocket socket = new ServiceSocket(this, webSocketClient);
        if (isStreamingConnection()) {
            connectionList.put(connectionId, socket);
        }

        //Start WebSocket client thread and upgrage HTTP connection
        webSocketClient.start();
        ...

bpapez avatar Feb 17 '14 17:02 bpapez

Thanks a lot for the suggestion, I'll try to implement this shortly.

fshutdown avatar Feb 19 '14 00:02 fshutdown

I have the sam e problem, I'm using the latest released JMeterWebSocketSampler-1.0.2-SNAPSHOT.jar and the problem not solved yet, any clues?

montaro avatar Jul 01 '14 10:07 montaro

Hi bpapez,

How do you test with 320 concurrent users? I mean how to set up the test plan? Could you please show with a picture? Thanks a lot.

As I test with only 2 or more concurrent users (i.e., set thread number as 2 or more), the websocket connection establishment will be fail other than the last thread.

The error shown as:

Thread Name: Thread Group 1-5 Sample Start: 2015-08-23 11:24:22 CST Load time: 5030 Connect Time: 0 Latency: 0 Size in bytes: 0 Headers size in bytes: 0 Body size in bytes: 0 Sample Count: 1 Error Count: 1 Response code: Response message:

[Execution Flow]

  • Opening new connection
  • Using response message pattern ""
  • Using disconnect pattern ""
  • Waiting for the server connection for 5000 MILLISECONDS
  • Cannot connect to the remote server

[Variables]

  • Message count: 0

[Problems]

  • Unexpected error: null JMeter.plugins.functional.samplers.websocket.ServiceSocket.sendMessage(ServiceSocket.java:156) JMeter.plugins.functional.samplers.websocket.WebSocketSampler.sample(WebSocketSampler.java:136) org.apache.jmeter.threads.JMeterThread.process_sampler(JMeterThread.java:434) org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:261) java.lang.Thread.run(Unknown Source)

Response headers:

SampleResult fields: ContentType: DataEncoding: UTF-8

peer2peer avatar Aug 23 '15 03:08 peer2peer

Hello,

attached are the screenshots of the thread group and the websocket sampler of our test. As said we are testing with hundreds concurrent users.

However our product switched from websockets to server-sent events, which seem to not be supported by the WebSocketSampler plugin.

Regards, Benjamin

websocket-threadgroup websocket-sampler

bpapez avatar Oct 09 '15 07:10 bpapez

I encountered an issue today when working with very large numbers of websocketsamplers. The threads appear to be only closed when the test finishes via testEnded(). So when we were running 600 threads that lasted 10 minutes then looped forever we were getting out of memory exceptions.

It turned out that there was 30,000 client threads for the WebSocketSampler stuck in wait states. We've patched the issue by calling close(statusCode, statusText) in the onClose() method in ServiceSocket. I'll probably fork the project and address this issue which is about the 4th one we have fixed at work.

swordmaster2k avatar Nov 04 '15 21:11 swordmaster2k