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

Websocket requests are not being executed concurrently #627

Closed
luizbafilho opened this issue May 15, 2018 · 1 comment
Closed

Websocket requests are not being executed concurrently #627

luizbafilho opened this issue May 15, 2018 · 1 comment
Labels

Comments

@luizbafilho
Copy link
Contributor

When running the script below with --vus 5, instead of getting the connected message 5 times, one for each VU, we get the message just once.

import ws from "k6/ws";
import { check } from "k6";

export default function () {
    var url = "ws://echo.websocket.org";

    var response = ws.connect(url, {}, function (socket) {
        socket.on('open', function open() {
            console.log(`VU ${__VU} ==> connected`);
            socket.ping();
        });

        socket.on('ping', function () {
            console.log("PING!");
        });

        socket.on('pong', function () {
            console.log("PONG!");
        });

        socket.on('close', function close() {
            console.log('disconnected');
        });

        socket.on('error', function (e) {
            if (e.error() != "websocket: close sent") {
                console.log('An unexpected error occured: ', e.error());
            }
        });

        socket.setTimeout(function () {
            console.log('1 seconds passed, closing the socket');
            socket.close();
        }, 1000);
    });

    check(response, { "status is 101": (r) => r && r.status === 101 });
};

Running with 5 VUs and 1 iteration.

$ k6 run --vus 5 samples/websocket.js

          /\      |‾‾|  /‾‾/  /‾/
     /\  /  \     |  |_/  /  / /
    /  \/    \    |      |  /  ‾‾\
   /          \   |  |\  \ | (_) |
  / __________ \  |__|  \__\ \___/ .io

  execution: local
     output: -
     script: samples/websocket.js

    duration: -,  iterations: 1
         vus: 5, max: 5

INFO[0001] VU 5 ==> connected
INFO[0001] PONG!
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] disconnected
    done [==========================================================] 1 / 1

    ✓ status is 101

    checks................: 100.00% ✓ 1   ✗ 0
    data_received.........: 204 B   126 B/s
    data_sent.............: 204 B   126 B/s
    iteration_duration....: avg=1.6s       min=1.6s       med=1.6s       max=1.6s       p(90)=1.6s       p(95)=1.6s
    iterations............: 1       0.622171/s
    vus...................: 5       min=5 max=5
    vus_max...............: 5       min=5 max=5
    ws_connecting.........: avg=605.84ms   min=605.84ms   med=605.84ms   max=605.84ms   p(90)=605.84ms   p(95)=605.84ms
    ws_ping...............: avg=111.046319 min=111.046319 med=111.046319 max=111.046319 p(90)=111.046319 p(95)=111.046319
    ws_session_duration...: avg=1.6s       min=1.6s       med=1.6s       max=1.6s       p(90)=1.6s       p(95)=1.6s
    ws_sessions...........: 1       0.622171/s

Running with 5 VUs with 5 iterations.

k6 run --vus 5 -i 5  samples/websocket.js

          /\      |‾‾|  /‾‾/  /‾/
     /\  /  \     |  |_/  /  / /
    /  \/    \    |      |  /  ‾‾\
   /          \   |  |\  \ | (_) |
  / __________ \  |__|  \__\ \___/ .io

  execution: local
     output: -
     script: samples/websocket.js

    duration: -,  iterations: 5
         vus: 5, max: 5

INFO[0001] VU 4 ==> connected
INFO[0001] VU 2 ==> connected
INFO[0001] VU 3 ==> connected
INFO[0001] VU 5 ==> connected
INFO[0001] VU 1 ==> connected
INFO[0001] PONG!
INFO[0001] PONG!
INFO[0001] PONG!
INFO[0001] PONG!
INFO[0001] PONG!
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] disconnected
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] disconnected
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] disconnected
INFO[0002] disconnected
INFO[0002] 1 seconds passed, closing the socket
INFO[0002] disconnected
    done [==========================================================] 5 / 5

    ✓ status is 101

    checks................: 100.00% ✓ 5   ✗ 0
    data_received.........: 1.0 kB  711 B/s
    data_sent.............: 1.0 kB  711 B/s
    iteration_duration....: avg=1.43s      min=1.42s      med=1.43s      max=1.43s     p(90)=1.43s      p(95)=1.43s
    iterations............: 5       3.489127/s
    vus...................: 5       min=5 max=5
    vus_max...............: 5       min=5 max=5
    ws_connecting.........: avg=425.62ms   min=415.82ms   med=427.66ms   max=429.02ms  p(90)=428.79ms   p(95)=428.9ms
    ws_ping...............: avg=116.312543 min=106.473666 med=118.354512 max=119.56554 p(90)=119.310812 p(95)=119.438176
    ws_session_duration...: avg=1.42s      min=1.42s      med=1.43s      max=1.43s     p(90)=1.43s      p(95)=1.43s
    ws_sessions...........: 5       3.489127/s
@luizbafilho
Copy link
Contributor Author

This is the expected behavior, it doesn't matter the number of VUs if the number of iterations is specified it will only run the specified number

@na-- na-- mentioned this issue May 15, 2019
39 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant