S
S
Sergey Sokolov2020-05-16 12:31:29
stress testing
Sergey Sokolov, 2020-05-16 12:31:29

How to reproduce WebSocket network activity with minimum resources?

You need to test the game engine for load. Clients communicate only over WebSocket.
Connect, send one message, another message.

Now we use high-level Artillery.io and self-written tests in NodeJS to test different scenarios.

Is it possible, not with a full-fledged WebSocket client, but somehow quite “easy” to test for load, when only outgoing data is of concern?

Maybe remember the outgoing network packets - after all, they are the same for each stream? Open tens of thousands of connections, and send a finished package to each. What tool can do this?

For example, a scenario: you need to open wss://myserver.com:443/wsand send a message there {"type": "handshake"}, and after 10 seconds send another one{"type":"action", "value":"move"}

And I'm interested in how the server will pull it with 5 thousand, 10, 50, 250, 500 thousand simultaneous connections open for 10 seconds.

Here is an example of how Wireshark intercepts a WebSocket connection. It turns out that it is necessary to wait for at least one response from the server during the connection establishment.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Aves, 2020-05-16
@Aves

const net = require('net');
const crypto = require('crypto');

const handshake = `GET / HTTP/1.1
Host: 192.168.43.135:12345
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
Upgrade: websocket
Origin: file://
Sec-WebSocket-Version: 13
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4
Sec-WebSocket-Key: bKdPyn3u98cTfZJSh4TNeQ==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits

`;

const s = net.connect(8080);

s.on('data', d => {
  if (/HTTP\/1\.1 101 Switching Protocols/.test(d)) {
    s.write(composeFrame('{"type": "handshake"}'));
    setTimeout(
      () => s.write(composeFrame('{"type":"action", "value":"move"}')),
      10000
    );
  }
});

s.write(handshake);

function composeFrame(text) {
  const mask = crypto.randomBytes(4);
  return Buffer.from([
    0b10000001,
    0b10000000 | text.length,
    ...mask,
    ...[...Buffer.from(text)].map((e, i) => e ^ mask[i % 4])
  ]);
}

This works for ws, but for wss you will probably need a TLSSocket from tls.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question