spdy-http2 / node-spdy

SPDY server on Node.js
2.81k stars 196 forks source link

Random pauses when pushing to the client #189

Closed gujason721 closed 8 years ago

gujason721 commented 9 years ago

spdy

I tried to push a file (10k size) from spdy server to a spdy client. The performance is consistently worse than the http get. So I used wireshark to inspect the packets and noticed that when streaming from the server to the client, there is always a pause for the last chunk of data file (packet id 32). For multiple files, there are also some random pauses when streaming the data and leading to poorer performance than http.

indutny commented 9 years ago

Could you please share a test case with me? Also, in which browser does this problem manifest itself?

gujason721 commented 9 years ago

I was using both a node-spdy server and client for the experiment.

Server code:

var spdy = require('spdy');
var fs = require('fs');

var options = {

  key: fs.readFileSync('keys/server.key'),
  cert: fs.readFileSync('keys/server.crt'),
  ca: fs.readFileSync('keys/server.csr'), 
  windowSize: 1024 * 1024,
  autoSpdy31: false,
};

buffer = fs.readFileSync('./dataFiles/s1.txt');

var server = spdy.createServer(options, function(req, res) {

    var stream = res.push('/dataFiles/s1.txt',{'content-type': 'text/plain'});

    stream.on('acknowledge', function() {
          //console.log('stream ACK'); 

    });

    stream.on('error', function(err) {
          console.log('stream ERR'+err);
    });

    stream.end(buffer);

    res.end();

});

server.listen(8081, function(){
}); 

Client code:


var spdy = require('spdy');
var http = require('http');
var delay=[];
var pushCunt = 1;
var counter = 0;

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

var agent = spdy.createAgent({
  host: '9.12.248.233', 
  port: 8081,
});

agent.on('push', function(stream) {

  stream.on('error', function(err) {
    console.log('client push stream error');
  });

  stream.on('data', function(chunk){

  });

  stream.on('end', function(){
    counter++;

    delay[counter] = new Date()-start;

    if (counter==pushCunt){

      console.log("spdy %d %d",delay[1],delay[pushCunt]);
      process.exit();     

    }

  });

  //console.log(stream);
});

var start = new Date();

var reqPath = '/dataFiles/s1.txt';

var req = http.request({
  host: '9.12.248.233',
  path: reqPath,    
  agent: agent
}, function(res) {

res.on('data', function (chunk) {

});

res.on('end', function () {

      });

});

req.setNoDelay(true);
req.end();
indutny commented 8 years ago

Should be fixed now!