Comments (9)
what happens if you take out the flush
parameter?
from discussions.
Still takes the same amount of time 200+ ms.
from discussions.
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.
If I change that loop to only be 500 iterations, I still have the same problem. Only 4.1KB of data.
from discussions.
Same here. There is no difference.
from discussions.
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.
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.
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.
@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.
The above were for a 50mb json file.
from discussions.
Related Issues (20)
- Improving the Koa ecosystem by moving all Koa modules to the koajs organization! HOT 62
- Immutable empty query obj HOT 15
- How to exclude api router? HOT 1
- Access to XMLHttpRequest at 'https://localhost:3443/images' from origin 'http://localhost:4200' has been blocked by CORS policy
- Destroy Mounts
- Conditional middleware
- Support for spa server?
- how to reg two part to the same file
- learning koa 2 and updating examples:https://github.com/aline2013/koa2-examples
- how to set interval within stream
- Hosting mp3 file
- Either 404 or wrong content HOT 1
- Error jump URL when ctx.path is directory
- koa-static: heavy caching issue HOT 2
- Why do i need koa-static HOT 1
- 404 not found for everything HOT 2
- koajs/conditional-get: uws.http failure
- Using both koa-compress and koa-static , extremely slow when visit static files from 127.0.0.1 or localhost (from public address is fast), why? HOT 2
- Brotli compress is slow HOT 2
- @fl0w becomes @miwnwski HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from discussions.