The Socket:
-
It has the nature of a pipeline file, similar to a queue, fifO
-
Has a file descriptor
-
Programming interface (API)
IO multiplexing:
- A single thread handles multiple sockets
- Core issue: The kernel distributes messages
- Select model: Threads maintain a list of Socket FDS
- Epoll model: The kernel maintains an efficient binary search tree
Blocking IO (BIO) :
- The operation blocks the thread
- With CPU interrupts, the blocked thread goes to sleep and gives execution permission to another thread
- Advantages: 1. Does not occupy system resources when blocking. 2. The program is easy to understand
- Disadvantages: 1. A high concurrency scenario requires a high number of threads (resource usage); 2. Thread switching has costs
- Scope of application: General high concurrency scenarios can also be considered, especially large parallelism scenarios, such as chat except
Non-blocking IO (NIO) :
- The operation does not block the thread and returns NULL if not read
- How it works: A dedicated data structure is responsible for counting I/O as it occurs, allowing programs to listen for changes
Asynchronous IO (AIO) :
- Asynchronous programming (Future-based)
- Principle: Scheduling all Future computations using thread pool technology, coroutine technology, usually combined with Epoll and DirectMemory technology
IO N (new) :
-
NIO Channel design
-
DirectMapping
-
It’s essentially a buffer out of the heap
-
Optimization point: Reduce one copy
-