MrSwitch / esi

Edge Side Includes processing for Node environments
https://www.npmjs.org/package/esi
23 stars 8 forks source link

Slowing page down significantly #3

Open iObject opened 9 years ago

iObject commented 9 years ago

Trying to implement in a Sails.io project but it's taking pages over a minute to render. Any suggestions?

MrSwitch commented 9 years ago

This could be HTTP request latency.

But the project could do with some benchmarks. So if you could include a problematic initial page and any external fragments it requires. Then we can add it to the testsuite to monitor performance.

iObject commented 9 years ago

The app won't hit a public facing domain for a few weeks due to security policies. I'll see if I can replicate in a fresh sails.io app.

MrSwitch commented 9 years ago

The benchmark should not be constrained by network requests.

What i meant was to create a series of files in a spec/mocks directory, i.e.

specs/mock/in.html
specs/mock/includewidget1.html
specs/mock/includewidget2.html
specs/mock/out.html
.... etc

The page "in.html" could be your page which includes ESI markup and is slow to process, the HTTP requests to includeWidget2.html could be stubbed.

This would let us monitor the performance impact of parsing a large page through the ESI module sandboxed from network requests.

darrennolan commented 9 years ago

I'm also facing page slow when using esi includes. My page includes are served from the same box, I see immediate request hits - but sometimes they stall either indefinitely or for long periods of time, before the route is actually hit back.

Page sizes are crazy small.

darrennolan commented 9 years ago

Actually this might be entirely unrelated, I may have jumped the gun. I'm still investigating the slowdowns on our side. Cheers.

indieisaconcept commented 8 years ago

A little late to this but I think the following may be contributing to the issue.

// Overwrite the write function

res.write = function( chunk, encoding ){

    if( !chunk ){
        // dont do anything
        return;
    }

https://github.com/MrSwitch/esi/blob/master/index.js#L103

Here res.write returns early if there is no chunk to be processed. However this should actually end the request, rather than doing nothing since this overrides the default res.write.

The following seems to address it.

if( !chunk ){ return original_end.call( res ); }

@MrSwitch thoughts?