4

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?

2
  • You are right. Nginx can't serve two or more requests concurrently in one worker. Commented Jun 15, 2011 at 8:05
  • 1
    @CyberDem0n,what about the filter pipelining thing? Theoretically,I don't think it's possible in a single process without threading. Commented Jun 15, 2011 at 8:13

1 Answer 1

1

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); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.