Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support compression in websockets #611

Closed
wallenZhao2046 opened this issue May 2, 2018 · 4 comments
Closed

Support compression in websockets #611

wallenZhao2046 opened this issue May 2, 2018 · 4 comments

Comments

@wallenZhao2046
Copy link

I have used K6 in websocket performance test. While the content from server is compressed, and I got "�0E�e�!�56���j0&��v!�{�:�9�^�" printed in console. I used nodejs code to handle the same message from server. I got the right text.

So my question is how to decode compressed text in K6?

my K6 script is

socket.on('message', function (data) {
      console.log(typeof (data));
      console.log(data.length)
      if (data.length < 200) {
        // I got "�0E�e�!�56���j0&��v!�{�:�9�^�" in console
        console.log(data);
      }
      // I tried to decode it got "incorrect header check"
      let text = pako.inflate(data, { to: 'string' }); 
    }

If I used the following JS script, I got the correct text to inflate it to plain text.

ws.on('message', function (data) {

        console.log('-------- begin -------');
        // I got <Buffer 1f 8b 08 00 00 00 00 00 00 00 2d 8b 4b 0a 80 20 14 45 f7 72 c7 21 f9 1b e4 6e 34 1f 14 12 49 5e 47 d1 de 33 68 7a 3e 37 f6 8c 80 c4 b5 b7 4c 4c 68 3d in console
        console.log(data);
        console.log('-------- end -------');

        let text = pako.inflate(data, {
            to: 'string'
        });
        // msg is " msg: {"id":"btcusdt","subbed":"market.btcusdt.depth.step0","ts":1525243319443,"status":"ok"} "
        console.log('msg: ' + text);
    })
@na--
Copy link
Member

na-- commented May 2, 2018

I already answered in the stackoverflow question, but I'll copy it here for posterity 😄

As I mentioned in the [previous] GitHub issue, it seems like pako's browserify version may have some issues when you specify { to: 'string' } in the options. Instead you should be able to do something like this:

let binText = pako.inflate(data);
let strText = String.fromCharCode.apply(null, binText);
console.log(strText);

Looking at this again, it seems like there is an official RFC 7692, which specifies websocket compression. So, if possible, I think we should actually natively support it directly in k6 so you don't have to rely on slow and external JS libraries like pako. Seems like it would be fairly straightforward, since the library we use for websockets seems to support compression: https://godoc.org/github.com/gorilla/websocket#Dialer.EnableCompression

@wallenZhao2046
Copy link
Author

I have tried to update ws.go and rebuild to support compression.
image

But got the same error message as below
image

@na-- na-- changed the title How to decode compressed text in websocket ? Support compression in websockets May 2, 2018
@na--
Copy link
Member

na-- commented May 2, 2018

I slightly edited the title so we can use this issue for adding native websocket compression support in k6, without the need for external JS libraries. I also reopened the old issue so we can use it for tracking down the likely JS bug in k6, since it would be a good idea to find and fix it regardless of the native compression support.

@na--
Copy link
Member

na-- commented Oct 21, 2021

Closed by #2162

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants