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

Concurrently route requests #5

Merged
merged 4 commits into from
Mar 24, 2015
Merged

Conversation

willfrew
Copy link
Contributor

Background:
My use-case for multifetch was to get around Chrome's 6 connections to the same origin limit.
Unfortunately, since most of my sub-queries do fairly heavy database queries, processing each request sequentially was resulting in unacceptable response times compared to creating a separate connection for each query.

So, I added support for routing multiple requests through express concurrently (see README.md additions).
Internally, we use async.eachLimit to fire off multiple queries through express at the same time and then queue up the resulting streams which are streamed out to the client sequentially. The next query is only routed through express when the first stream is fully piped out and so on.

By default, I made sure that multifetch was still processing requests sequentially so as to maintain backwards compatibility.

// stream into the resource queue.
var fetchResource = function(key, callback) {
var messages = createMessages(request, query[key]);
process.nextTick(function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is nextTick needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, you're right, it's not needed! I think it's an artifact from some previous playing I was doing. Removed.

@kapetan
Copy link
Contributor

kapetan commented Mar 18, 2015

I've added a couple of comments, but otherwise it looks good.

kapetan added a commit that referenced this pull request Mar 24, 2015
@kapetan kapetan merged commit 8b989a8 into debitoor:master Mar 24, 2015
@kapetan
Copy link
Contributor

kapetan commented Mar 24, 2015

Thanks for this. Released in v1.1.0.

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

Successfully merging this pull request may close these issues.

2 participants