13
- What is non-blocking I/O?
- What are the uses of a language with non-blocking I/O?
- What are the practical applications of non-blocking I/O?
It certainly doesn’t come into question of opinion, so I wanted to know the possible problems.
13
It certainly doesn’t come into question of opinion, so I wanted to know the possible problems.
12
What is non-blocking I/O?
Is the ability to do in and out operations (access file system, database, network, servers, etc.) without the application being prevented from performing other things in parallel.
It is very common for input and output to take "long time" because of the hardware that controls this operation, but hardly consumes processing, it would be a waste not to let the application do other things, so some techniques can be applied to parallelize execution, each meeting a different need. The most popular currently is the asynchronicity.
Blocking applications are especially bad when doing user interaction.
There are cases that even the operation done on a server can be impaired by blocking and make the user receive delayed information.
There may be operations that block the opposite. Imagine an application waiting for the user to type something. It is usually a blocking operation. But it does not have to be, there is how to allow other operations to be performed in parallel, the so-called "in background.".
Overall it is advantageous to improve the user experience.
What are the uses of a non-blocking I/O language? What are the practical applications of non-blocking I/O?
This feature is just a specific point of the language. It often has more to do with the library than with the language.
Any operation at the moment that there is interaction directly with the user, whether by console, GUI, browser, etc., if it is blocking prevents the user to do other tasks, not even to use the keyboard. Moreover, the system may stop responding, and not only the user may try to close it, but even the operating system can do this preventively.
So if you’re going to do a longer operation, make it non-blocking, so the moment the operation is waiting for the hardware response from and/s the CPU remains free to do other things.
If you make a loop waiting for the answer it will probably be blocking. If you create a system of events and notifications (observer standard) saves a lot of processing. The code says he wants to be notified when the operation is over and has an answer, so he doesn’t have to keep repeating the question whether he already has an answer or not. It’s so much smarter.
Loop-shaped:
pede pra fazer algo
tá pronto?
tá pronto?
tá pronto?
tá pronto?
tá pronto?
tá pronto?
tá pronto?
tá pronto?
.
.
.
em algum momento responde "sim" e continua daqui
Smart code:
faça seu trabalho e me avise quando terminar -> (outra operação demorada executa, notifica)
terminou, continuo daqui
Look at the difference in work.
With this the processor is not working to control the loop and is free to meet other demands. Obviously just doing this does not parallelize anything, the parallel can occur with processes, threads or some language control or library, such as Polling, Event flags, Signals, green threads, callback functions, Channels, registred I/O.
Languages that have a mechanism for not blocking execution can greatly facilitate the execution of multiple simultaneous requests on servers without wasting resources because it is blocked or managing the competition, resulting in the end a much greater service capacity.
Especially on web server it is common to do more I/O access than processing, there is advantage in doing so, and that is why almost all modern languages (some not so modern) have mechanisms on their own or in the library that allow non-blocking operations.
Browser other questions tagged terminology characteristic-language language-independent io
You are not signed in. Login or sign up in order to post.
I think that here which may be what you seek!
– Marconi
@Marconi Thank you very much, I did not know that there were these terms. It can help anyone who wants to search the same thing for other names.
– Asura Khan
Good that can clarify @Asurakhan!
– Marconi
The answer is already quite complete, I just wanted to add that the term
non-blocking
means that the function does not block theThread
, That is, the execution in the current Thread continues without the task being complete, and does not apply only to I/O. This is only possible with some kind of parallelism. On the other hand, in a functionblocking
the next line is executed only when the current one has finished its task.– user178974