当前位置:网站首页>理解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 模式,简化了程序编写,有效的请求才启动线程,它的特点是先由操作系统完成后才通知服务端程序启动线程去处理,一般适用于连接数较多且连接时间较长的应用。
边栏推荐
- JMeter -- interface test 2
- 网上炒股开户安不安全?
- 【无标题】
- A - deep sea exploration
- [go ~ 0 to 1] the next day, June 25, switch statement, array declaration and traversal
- Trailing Zeroes (II)
- How to solve the problem of high concurrency and seckill
- 如何抑制SiC MOSFET Crosstalk(串擾)?
- What are the advantages of a differential probe over a conventional probe
- Operating principle of Rogowski coil
猜你喜欢

Deployment of MySQL database in Linux Environment

抖音服務器帶寬有多大,才能供上億人同時刷?

Operating principle of Rogowski coil

Webrtc advantages and module splitting

Postman interface test

【大案例】学成在线网站

Discussion on the improvement and application of the prepayment system in the management of electricity charge and price

Wasmedge 0.10.0 release! New plug-in extension mechanism, socket API enhancement, llvm 14 support

JMeter -- interface test 2
![DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...](/img/90/425965ca4b3df3656ce2a5f4230c4b.jpg)
DELL R730服务器开机报错:[XXX] usb 1-1-port4: disabled by hub (EMI?), re-enabling...
随机推荐
Postman interface test
State machine program framework
How do people over 40 allocate annuity insurance? Which product is more suitable?
Construire le premier réseau neuronal avec pytorch et optimiser
为什么函数模板没有偏特化?
What are the advantages of a differential probe over a conventional probe
ffmpeg推流报错Failed to update header with correct duration.
containerd1.5.5的安装
Rman Backup Report Ora - 19809 Ora - 19804
Guangzhou: new financial activities and new opportunities for enterprises
Implement global double finger long press to return to the desktop
Discussion on the practice of fire emergency lighting system in the field of building electrical design
Anniversary party
What is the bandwidth of the Tiktok server that can be used by hundreds of millions of people at the same time?
Chrome devtools
手机买同业存单基金开户选哪家证券公司比较好,比较安全呢
Loss损失函数
Loggerfactory uses log4j Parameter introduction of properties
Common test method used by testers --- orthogonal method
[untitled]