当前位置:网站首页>理解IO模型
理解IO模型
2022-06-28 09:00:00 【知知之之】
BIO
同步并阻塞(传统阻塞型),服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不作任何事情会造成不必要的线程开销。

NIO
同步非阻塞,服务器实现模式为一个线程处理多个请求(连接),即客户端发送的连接请求会被注册到多路复用器上,多路复用器轮询到有 I/O 请求就会进行处理。

Selector
Selector多路复用器算是对linux下的select/poll/epoll进行封装,selector可以有多种实现,linux系统下默认使用epoll的实现方式。
- Java 的 NIO 使用了非阻塞的 I/O 方式。可以用一个线程处理若干个客户端连接,就会使用到 Selector(选择器)。
- Selector 能够检测到多个注册通道上是否有事件发生(多个 Channel 以事件的形式注册到同一个 selector),如果有事件发生,便获取事件然后针对每个事件进行相应的处理。
- 只有在连接真正有读写事件发生时,才会进行读写,减少了系统开销,并且不必为每个连接都创建一个线程,不用维护多个线程。
- 避免了多线程之间上下文切换导致的开销。
AIO
异步非阻塞,AIO 引入了异步通道的概念,采用了 Proactor 模式,简化了程序编写,有效的请求才启动线程,它的特点是先由操作系统完成后才通知服务端程序启动线程去处理,一般适用于连接数较多且连接时间较长的应用。
边栏推荐
- MATLAB小技巧(20)矩阵分析--主成分回归
- Three body attack (three-dimensional split plus two points)
- SQL注入之文件读写
- 用Pytorch搭建第一个神经网络且进行优化
- Loggerfactory uses log4j Parameter introduction of properties
- Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
- 【无标题】
- How to implement two factor authentication MFA based on RADIUS protocol?
- 网上炒股开户安不安全?
- Tree
猜你喜欢

Postman interface test

Explain observer mode

Superimposed ladder diagram and line diagram and merged line diagram and needle diagram

Guangzhou: new financial activities and new opportunities for enterprises

"Jianzhi offer" -- Interview Question 4: finding two-dimensional arrays
![[untitled]](/img/bb/213f213c695795daecb81a4cf2adcd.jpg)
[untitled]

JMeter -- interface test 2

SQL injection file read / write

Discussion on the practice of fire emergency lighting system in the field of building electrical design

Kali installation configuration
随机推荐
Guangzhou: new financial activities and new opportunities for enterprises
DEJA_VU3D - Cesium功能集 之 051-地形开挖完美实现
Assertions used in the interface automation platform
Implement global double finger long press to return to the desktop
与普通探头相比,差分探头有哪些优点
Explain observer mode
A - Bi-shoe and Phi-shoe
Application of energy management system in iron and steel enterprises
Anniversary party
Common faults and solutions of Substation
RMAN backup message ora-19809 ora-19804
Common test method used by testers --- orthogonal method
实现全局双指长按返回桌面
Power data
Superimposed ladder diagram and line diagram and merged line diagram and needle diagram
Basic operation of PMP from applying for the exam to obtaining the certificate, a must see for understanding PMP
抖音服务器带宽有多大,才能供上亿人同时刷?
【.NET6】gRPC服务端和客户端开发案例,以及minimal API服务、gRPC服务和传统webapi服务的访问效率大对决
[untitled]
The 6th smart home Asia 2022 will be held in Shanghai in October