GithubHelp home page GithubHelp logo

Comments (9)

jonathanong avatar jonathanong commented on May 7, 2024

what happens if you take out the flush parameter?

from discussions.

kingjerod avatar kingjerod commented on May 7, 2024

Still takes the same amount of time 200+ ms.

from discussions.

jonathanong avatar jonathanong commented on May 7, 2024

it's probably your data payload being gigantic. if you streamed it, it should be a lot faster, at least for first byte

from discussions.

kingjerod avatar kingjerod commented on May 7, 2024

If I change that loop to only be 500 iterations, I still have the same problem. Only 4.1KB of data.

from discussions.

gugadev avatar gugadev commented on May 7, 2024

Same here. There is no difference.

from discussions.

fl0w avatar fl0w commented on May 7, 2024

I can't reproduce this. Tried using both node 7.2.1 and 8.1.0, on macOS 10.12.5.

$ time curl localhost:3000 &> /dev/null

real	0m0.018s
user	0m0.004s
sys	0m0.004s
// copy-pasted from above.
const Koa = require('koa');
const app = new Koa();

app.keys = ['key1'];
app.use(require('koa-compress')({
  flush: require('zlib').Z_SYNC_FLUSH
}));

let data = [];
for(let i = 0; i < 50000; i++) {
  data.push('hello');
}
app.use(async (ctx, next) => {
  ctx.body = data;
});
app.listen(3000);
console.log('Listening on port 3000.');

Either this has been fixed or there's some OS variable not provided here.

from discussions.

greim avatar greim commented on May 7, 2024

I found similar behavior in Chrome devtools and also curl, using a 15MB json file full of enron emails. ~10s to download 10 files compressed, ~2.5s to download 10 files uncompressed. All downloads in serial order.

I guess it doesn't surprise me that gzip would be the bottleneck over localhost, but I worry parallel requests would saturate the core. Or maybe this is normal gzip penalty? At an old job we used to upload pre-gzipped files to our CDN to avoid such slowdowns.

// server code
const Koa = require('koa');
const app = new Koa();

app.keys = ['key1'];
app.use(require('koa-compress')({
  flush: require('zlib').Z_SYNC_FLUSH
}));

app.use(async (ctx, next) => {
  ctx.set('content-type', 'application/json; charset=UTF-8')
  ctx.body = require('fs').createReadStream(__dirname + '/enron.json', 'utf8');
});
app.listen(3000);
console.log('Listening on port 3000.');
// devtools console
(async () => {
  const start = Date.now();
  for (let i=0; i<10; i++) {
    await fetch('/').then(r => r.text());
  }
  const end = Date.now();
  console.log(end - start);
})()
# curl command
curl -v -H "Accept-Encoding: gzip" "http://localhost:3000/?foo=[0-9]" > /dev/null

koa-compress version: 3.0.0
Node version: 8.x and 10.x
OS: Mac OS 10.11.6

from discussions.

tracker1 avatar tracker1 commented on May 7, 2024

Try setting the compression level a bit lower {level:7}, should help. This should probably be the default, iirc zlib defaults to 9, which is quite a bit more expensive.

from discussions.

greim avatar greim commented on May 7, 2024

@tracker1 - I don't think 9 is the default. zlib.Z_DEFAULT_COMPRESSION reports as being -1 for me. Setting to Z_BEST_SPEED (1) definitely speeds things up. Setting to 7 slows it down considerably from the default.

screen-shot-2018-10-29-at-4 14 23-pm

The above were for a 50mb json file.

from discussions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.