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

Optimize already encoded streams #50

Closed
wants to merge 1 commit into from
Closed

Conversation

Rush
Copy link

@Rush Rush commented Aug 26, 2015

I was doing some performance tests with passing already encoded streams through http-master (https://github.com/encharm/http-master) (which utilizes expressjs/compression). Weirdly enough there was a big performance hit when doing many requests that simply passed through expressjs/compresison. My initial suspicion was that requests were being re-encoded but no ... the complexity of your on, end and write wrappers was enough to visibly degrade performance. This pull request restores the original function handlers after knowing that stream is not gonna be encoded.

It completely solved my issue. I would appreciate a merge.

@dougwilson
Copy link
Contributor

Sorry, this is not acceptable. Your change assumes that after we replaced those methods, another module did not also replace them.

If you can address that case, I will reconsider.

@dougwilson dougwilson self-assigned this Aug 26, 2015
@dougwilson dougwilson added the pr label Aug 26, 2015
@dougwilson
Copy link
Contributor

I quick test case you can run, is the following:

app.use(compression())
app.use(function (req, res, next) {
  var end = res.end;
  res.end = function () {
    console.log('clean up something')
    return end.apply(this, arguments)
  }
  next();
})
app.use(function (req, res, next) {
  res.setHeader('Content-Length', '3')
  res.end('hi!')
})

I just typed this out quickly, so please excuse any typos. With your changes, the "clean up something" should appear on the console (the content-length is there to help ensure we don't compress, which should trigger your added behavior).

@dougwilson
Copy link
Contributor

P.S. I'm really sorry, I didn't mean to sound harsh, I just keep getting this exact PR in various repos every so often, which has the issue hopefully highlighted by the code above. I'm all for solving any performance problems.

Perhaps, if you cannot get something working that plays well with other modules, can you share the performance traces showing exactly where we are slowing down and perhaps address them?

@Rush
Copy link
Author

Rush commented Aug 26, 2015

@dougwilson thanks for your input, and no it was not too harsh.

It appears that those performance problems were happening only on 1.4.4 but not on master, judging from the code, possibly having been fixed by 2086d11.

Sorry for rushing to implement a fix without properly checking if master is already working well.

As I cannot see a statistically significant performance difference with this fix on top of master, I am closing this PR.

Apologies for wasting your time.

@Rush Rush closed this Aug 26, 2015
@dougwilson
Copy link
Contributor

Ah, interesting. There were a bunch of performance improvements in the 1.5.0 release, so I suppose one of those fixed what you were seeing (which, is actually awesome to here, because I fixed those simply because they needed to be, rather than based on complaints!).

Also, you're not wasting my time :) I'm truly sorry if I came off harsh in the first response :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants