0

am sorry for this dumb question, but am really confused; and i hope you'll correct me where am wrong.

in the thread based servers (like Apache), i understand that for each client, a new 'worker' will be created for him to serve all his needs.

in the event driven (like Nginx and Tornado), this comes my confusion, espetially where there is a Not Thread Safe like the Python's GIL; from what i understand, there is ONE SINGLE LOOP that will handle ALL client requests, so as my dumb understanding, if there are 10 000 simultanous connections, i dont see how to serve ALL those 10 thousend requests!

Abdelouahab Pp
  • 4,252
  • 11
  • 42
  • 65

1 Answers1

2

In event-driven servers you just handle connections (read()s and write()s from specific connections, really) one after the other, using non-blocking calls. You usually use some call to multiplex between connections (select(), poll(), ...), which tell you which connections need to be serviced, and you service them in turn.

ninjalj
  • 42,493
  • 9
  • 106
  • 148
  • so why we cant combine between event-driven and thread-based servers? – Abdelouahab Pp Dec 02 '12 at 11:31
  • 1
    You can. e.g: you may have a thread per CPU-core, where each thread is event-driven. You may also have worker threads to deal with dynamic page generation (PHP, JSP, ...), and serve static content (images, ...) through "normal" event-driven threads. – ninjalj Dec 02 '12 at 11:50
  • the problem is that Python (CPytohn) has the GIL, and as said Tornado handles the 10k connection, so i was 'shocked' that can happen! if 10k simultanuous connection happens, then, if an operation has 1 second, il will be splited to 1/10k ? – Abdelouahab Pp Dec 02 '12 at 11:54
  • 1
    It depends. Tornado can probably handle 10k/s typical connections, but physical limits still exist: if you don't have the bandwith, you won't be able to handle 10k connections asking for a large file download.In that case, when servicing each connection, the ideal would be for your server to only send (beware: formula made up on the spot) _(bandwith*desired max latency/active connections)_ each iteration. – ninjalj Dec 02 '12 at 12:13
  • sorry but what do you mean by bandwidth, is if i use a 2Mb ADSL (Algeria is the best i can do), this is the value? – Abdelouahab Pp Dec 02 '12 at 12:42
  • 1
    In that case, it would be your outbound bandwidth, which is probably much lower than that. Busy servers should have much more bandwidth. – ninjalj Dec 02 '12 at 12:46
  • so then in my case i should think about 1k problem instead of 10k :p – Abdelouahab Pp Dec 02 '12 at 12:49
  • on last question: if event driven only reads and writes some specific connection, then what thread based do? – Abdelouahab Pp Dec 02 '12 at 13:16