Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maximum websocket connections in browsers

I want to do some stress test against my websocket server runnig this javascript example in my browser (chrome) below:

  function create_ws() {
    var ws=new WebSocket("ws://127.0.0.1/");
    ws.onopen=function(evt){
      var binary = new Uint8Array(2);
      binary[0]=1;
      binary[1]=2;
      ws.send(binary.buffer);                  
    };
    ws.onclose=function(evt){};
    ws.onmessage=function(evt){};
    ws.onerror=function(evt){};
  }

 var connections = [];
 var numberOfconnections=100;

 for(var i = 0; i < numberOfconnections; i++) {
  connections.push(create_ws());
 }

The problem is the script above let me run only about 100 connections at the same time. If i increase numberOfconnections to 300 it throws following error: WebSocket connection to 'ws://127.0.0.1/' failed: Error in connection establishment: net::ERR_INSUFFICIENT_RESOURCES

Is there a way to increase the number of websocket connections in browser?

like image 840
maciekm Avatar asked Oct 20 '22 01:10

maciekm


2 Answers

Try to open new tabs with your stress test manually or with window.open in code.

like image 69
Roman Dibikhin Avatar answered Nov 02 '22 11:11

Roman Dibikhin


Looks like the limit for chromium is set to 256 per the discussion below:

Chromium Discussion

It's possible other browsers have different limits. As I only use so many connections for stress testing, I plan to open a few windows to go outside the limit.

like image 43
SmujMaiku Avatar answered Nov 02 '22 13:11

SmujMaiku