Daniil Iaitskov
Daniil Iaitskov

Reputation: 6039

How to increase WebSocket throughput

I need to pull data from a lot of clients connecting to a java server through a web socket.

There are a lot of web socket implementations, and I picked vert.x. I made a simple demo where I listen to text frames of json, parse them with jackson and send response back. Json parser doesn't influence significantly on the throughput.

I am getting overall speed 2.5k per second with 2 or 10 clients.

Then I tried to use buffering and clients don't wait for every single response but send batch of messages (30k - 90k) after a confirmation from a server - speed increased up to 8k per second.

I see that java process has a CPU bottleneck - 1 core is used by 100%. Mean while nodejs client cpu consumption is only 5%. Even 1 client causes server to eat almost a whole core.

Do you think it's worth to try other websocket implementations like jetty? Is there way to scale vert.x with multiple cores?

After I changed the log level from debug to info I have 70k. Debug level causes vert.x print messages for every frame.

Upvotes: 1

Views: 3161

Answers (2)

FrankG
FrankG

Reputation: 543

Something doesn't sound right. That's very low performance. Sounds like vert.x is not configured properly for parallelization. Are you using only one verticle (thread)?

The Kaazing Gateway is one of the first WS implementations. By default, it uses multiple cores and is further configurable with threads, etc. We have users using it for massive IoT deployments so your issue is not the JVM. In case you're interested, here's the github repo: https://github.com/kaazing/gateway

Full disclosure: I work for Kaazing

Upvotes: 0

meshuga
meshuga

Reputation: 131

It's possible specify number of verticle (thread) instances by e.g. configuring DeploymentOptions http://vertx.io/docs/vertx-core/java/#_specifying_number_of_verticle_instances

You was able to create more than 60k connections on a single machine, so I assume the average time of a connection was less than a second. Is it the case you expect on production? To compare other solutions you can try to run https://github.com/smallnest/C1000K-Servers

Upvotes: 1

Related Questions