Thread vs Event Loop - network programming (language agnostic)

I am writing a simple daemon to receive data from N many mobile devices. The device will poll the server and send the data it needs as simple JSON. In general terms, the server will receive data and then "do with it."

I know that this topic has been beaten up a bunch of times, but it's hard for me to understand the pros and cons.

If threads or events (think Twisted in Python) work better for this situation before concurrency and scalability? The event model seems to make more sense, but I wanted to interview you guys. The data goes to → Process data → waiting for more data. What if "doing things" was something very intense in the computing field? What to do if the “making material” was very intense (for example, pasting into a database). Will this block the event loop? What are the advantages and disadvantages of each approach?

+4
source share
3 answers

Python, . , , . , Python -, CPU.

, , , gevent .., - . , / - (, / db), , - (, WebSockets) . Python , , .

, , , , , . . . / . , , .

Python, , , , (google "Python GIL", ). Python , " ", , , , . ( ..), , - (. http://en.wikipedia.org/wiki/C10k_problem)

, , /.

+5

, " ".

, // (python )

, , . , unix, , Windows.

, , -:

, , , , :

  • , ,
  • ​​ , , , , .

1 , /

2 . (select/poll/epoll/kqueue/WaitForMultipleObjects/CoreFoundation/libevent ..)

/ ( ).

: Twisted python, Node.js Javascript, libevent/libev C ++. , , , .

-, , - , .

, - (), / (), -

+3

. ? ?

, ( -) . .

, .

0
source

Source: https://habr.com/ru/post/1539940/


All Articles