当前位置:网站首页>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 ;
边栏推荐
- 编译与链接
- 伏英娜:元宇宙就是新一代互联网!
- 2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
- 初识C语言(3)
- JS realizes the function of one click Copy
- 安装postgis时报找不到“POSTGIS_VERSION”这个函数
- Object detection: object_ Detection API +ssd target detection model
- 关于双指针的思想总结
- 这个报错是什么鬼啊,不影响执行结果,但是在执行sql时一直报错。。。连接maxComputer是使用
- Is there any way for Youxuan database to check the log volume that the primary cluster transmits to the standby cluster every day?
猜你喜欢

全屋WiFi方案:Mesh路由器组网和AC+AP

MySQL gets the maximum value record by field grouping

Fu Yingna: Yuan universe is the new generation of Internet!
![[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation](/img/4b/150689d5e4809ae66a4297915ecd0c.png)
[paper translation] vectornet: encoding HD maps and agent dynamics from vectorized representation

Zhihuijun, a genius of Huawei, made a modular mechanical keyboard, which caused an earthquake in the geek circle. Netizens: This is the real customization

Design of environment detection system based on STM32 and Alibaba cloud

Applet: Area scrolling, pull-down refresh, pull-up load more

Blood cases caused by < meta charset=UTF-8> -- Analysis of common character codes

VScode连接ssh遇到的问题

关于双指针的思想总结
随机推荐
[deep learning CPU (part outside) - virtual memory]
当我从数据库获取到了winfrom特定的控件ID之后我需要通过这个ID找到对应的控件,并对控件的TEXT文本进行赋值这该怎么做
There is a special cryptology language called asn.1
Const read only variable constant
Codeforces Round #810 (Div. 2) D. Rain (线段树差分)
Some problems about pointers
SQL语句 关于字段转换怎么写
opengauss预检查安装
Pointer of pointer???...
请问,在sql client中,执行insert into select from job时,如何单
MPU6050
Pat a1069/b1019 the black hole of numbers
How to set the SQL execution timeout for flick SQL
[BGP] small scale experiment
C language to achieve three chess game (detailed explanation)
有一种密码学专用语言叫做ASN.1
Asp. Net MVC, how can the controller in the folder jump to the controller in the root directory?
Why do I delete the original record (OP d) and then add a new one in Kafka when I update MySQL data
AssertionError(“Torch not compiled with CUDA enabled“)
数据集成这个地方的过滤条件该咋写,用的啥语法?sql语法处理bizdate可以不