A
A
aldexnotproger2020-11-17 19:39:14
Asynchronous programming
aldexnotproger, 2020-11-17 19:39:14

How does asynchrony work?

Hello.
For several days now, I've been scouring the Internet for how asynchrony works. More specifically, I can't understand how asynchrony works on the server side, for example.
This is how I see it now: The server is waiting for the client. The client sends a request to the server and goes about its business. The server receives the request, processes it, and then sends it to the client.
And if there are, for example, 10,000 customers? As I understand it, two options will help here: multithreading or asynchrony (although, as I understand it, asynchrony is implemented due to multithreading). So, how is asynchrony implemented in this case so as not to block the server socket that accepts the connection? Use separate threads for connection and processing?

I want to note that I recently began to study this topic. We flew the issue compiled on the go, so there may be errors and inaccuracies.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-11-17
@aldexnotproger

https://ru.stackoverflow.com/a/816006/204271

V
Vladimir Korotenko, 2020-11-17
@firedragon

Bad and incomprehensible. And everything is wrapped in magic that needs to be understood.
Under the hood, there is the same pool of threads that was used in the event model and when you held the threads with your hands.
And the bad thing is that if you do not catch an exception, it pops up in the most non-obvious place.
Second, all this fun is spent resources.
From good. You can indeed leave heavy code to run in the background.
But!
* Do not take up all the memory
* Do not exceed the number of threads
* Do not exceed the limit of connections to the base
* Do not gobble up all the IO
* Do not kill the percentage
Otherwise, you are not limited :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question