Reputation: 7793
The really cool part about the filter chain is that each filter doesn't wait for the previous filter to finish; it can process the previous filter's output as it's being produced, sort of like the Unix pipeline. (from here)
I guess the above is talking about such code at the end of each filter:
if (!chain_contains_last_buffer)
return ngx_http_next_body_filter(r, in);
That is,nginx chains the filters one by one.
But as it's at the end of each filter,it has to wait until current filter is done. I don't see how nginx manages to make each filter doesn't wait for the previous filter to finish
.
So the above is about the concurrency of nginx filter,next is about the concurrency of nginx request handling:
As we know nginx uses epoll
to deal with requests:
events = epoll_wait(ep, event_list, (int) nevents, timer);
for (i = 0; i < events; i++) {
...
rev->handler(rev);
}
With code like above,I don't think nginx can handle two request concurrently,it can only do it one by one(each handler
finishes its job fast enough so the next request gets handled pretty soon),right?
Or is there any gotcha I'm missing?
Upvotes: 4
Views: 811
Reputation: 32392
There is a way to test this. Write a filter that sleeps, and use it in the filter chain. Then test to see if you can get nginx to serve a request while a previous request is sleeping.
Then run the test again, but this time don't let the filter sleep, make it wait using select timeouts like so:
/* wait 1.5 secs */
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 500000;
select(0, NULL, NULL, NULL, &tv);
Upvotes: 1