当前位置:网站首页>Differences and principles of bio, NiO and AIO
Differences and principles of bio, NiO and AIO
2022-07-29 04:12:00 【Fanzongshen】
BIO、NIO、AIO The differences and principles of
1.io Model
JAVA BIO: Synchronize and block , The server implements a pattern of one thread per connection , That is, when the client has a connection request, the server needs to start a thread and process , If this connection doesn't do anything, it will cause unnecessary overhead , Of course, it can be improved through the thread pool mechanism
JAVA NIO: Synchronous nonblocking , The server implementation mode is one request, one thread , That is, the connection requests sent by the client will be registered on the multiplexer , The multiplexer polls the connection to have IO Start a thread to process when requested
JAVA AIO(NIO2): Asynchronous non-blocking , The server implementation mode is a valid request for a thread , Client's I/O All requests were made by OS First complete and then inform the server application to start the thread for processing ;
2. Use scenarios
BIO It is suitable for architectures with a small number of connections and a fixed number of connections , This approach is more demanding on server resources , Concurrency is limited to the application ,JDK1.4 The only choice before , But the program is straightforward and easy to understand .
NIO The method is suitable for a large number of short connections ( Light operation ) The architecture of , For example, chat servers , Concurrency is limited to the application , Programming is complicated ,JDK1.4 Start supporting .
AIO Mode is used for many and long connections ( Re operation ) The architecture of , Like the album server , Call full OS Participate in concurrent operations , Programming is complicated ,JDK7 Start supporting .
3.BIO Synchronize and block
tomcat The traditional BIO( Synchronous blocking IO Model )+ Thread pool mode , For 100000 or even millions of connections , Tradition BIO The model is powerless :
① Threads are expensive to create and destroy , stay linux in , A thread is essentially a process , Creation and destruction are heavyweight system functions
② The thread itself occupies a large amount of memory , image java The thread stack of is generally allocated at least 512K-1M Space , If the system thread is too high , Memory usage is a problem
③ High switching cost of threads , When the operating system switches threads , The context of the thread needs to be preserved , Then make a system call , If the number of threads is too high, the time of thread switching may be even greater than the time of thread execution , The performance brought by this time is the system load High ,CPUsy The usage rate is very high
④ It's easy to create jagged system load . The system load is expressed in the number of active threads or CPU The core number , Once the number of threads is high but the external network environment is not very stable , It's easy to cause a large number of requests to return at the same time , Activate a large number of blocking threads, so that the system load pressure is too high .
4.NIO Synchronous nonblocking
NIO be based on Reactor, When socket Stream readable or writable socket, The operating system will notify the reference program accordingly to handle , The application then reads the stream to the buffer or writes it to the operating system . That is to say , Not a link should correspond to a processing thread , Instead, a valid request corresponds to a thread , When the connection has no data , There is no worker thread to handle it
nio Only acceptor The service thread of is blocked , Other read / write threads register events , The thread resource area is called to execute only when a read-write event is activated , It won't be blocked all the time waiting for reading and writing ,Reactor The bottleneck lies in acceptor Implementation , Read and write events are also distributed here .
5.AIO Asynchronous non blocking IO
AIO You need a link to register read / write events and callback methods , When reading and writing , Just call API Of read or write The method can , Both methods are asynchronous , For read operations , When there is a stream to read , The operating system passes a readable stream into read Method , And notify the application ; For write operations , When the operating system will write When the stream passed by method is finished writing , The operating system actively notifies applications
namely ,read/write Methods are asynchronous , After completion, the callback function will be actively called ;
边栏推荐
- pat A1041 Be Unique
- [principle] several ways of horizontal penetration
- Ssl== certificate related concepts
- 小程序:区域滚动、下拉刷新、上拉加载更多
- MySQL第四篇(完结)
- Pat a1069/b1019 the black hole of numbers
- Note: restframe work records many to one tables, how to serialize in that table (reverse query)
- Array as function parameter -- pointer constant / constant pointer
- 有一种密码学专用语言叫做ASN.1
- 索引的最左前缀原理
猜你喜欢
Data mining -- Introduction to the basis of association analysis (Part 1)
Object array merges elements according to a field
安装ros的laser_scan_matche库所遇到的问题(一)
Compilation and linking
UnicodeDecodeError: ‘ascii‘ codec can‘t decode byte 0x90 in position 614: ordinal not in range(128)
Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes
基于STM32和阿里云的环境检测系统设计
Three tier architecture of enterprise network
企业网的三层架构
Mmdetection preliminary use
随机推荐
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理
优炫数据库有办法查到主集群每天传给备集群的日志量吗?
Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
伏英娜:元宇宙就是新一代互联网!
JS realizes the function of one click Copy
Svg -- loading animation
[Openstack] keystone,nova
rman不标记过期备份
MPU6050
There is a special cryptology language called asn.1
Const char* and char*, string constants
“蔚来杯“2022牛客暑期多校训练营2 H
HCIP BGP
店铺排名问题,如何解决?
MySQL Part 3
Three tier architecture of enterprise network
有一种密码学专用语言叫做ASN.1
为什么opengauss启动的时候这么多的unknown?
数据挖掘——关联分析基础介绍(上)