当前位置:网站首页>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 ;
边栏推荐
- 伏英娜:元宇宙就是新一代互联网!
- 初识C语言(3)
- LCA board
- Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
- 2021 sist summer camp experience + record post of School of information, Shanghai University of science and technology
- “蔚来杯“2022牛客暑期多校训练营1 J Serval and Essay(启发式合并)
- HCIP BGP
- 大佬们flink的JDBC SQL Connector现在不支持所有的数据库吗,例如vertica?
- Wechat applet monitors sliding events on the screen
- Summary on the thought of double pointer
猜你喜欢

UCOS task switching process

RMAN do not mark expired backups

How to solve the problem of store ranking?

信号处理中的反傅里叶变换(IFFT)原理

企业网的三层架构

为什么opengauss启动的时候这么多的unknown?

MPU6050

Function pointer and callback function

Data mining -- Introduction to the basis of association analysis (Part 1)

Lua语言(stm32+2G/4G模块)和C语言(stm32+esp8266)从字符串中提取相关数据的方法-整理
随机推荐
Rhel8 patch package production
数据挖掘——关联分析基础介绍(上)
First ALV program 2
%s. %c, character constant, string constant, const char*, pointer array, string array summary
JS realizes the function of one click Copy
基于STM32和阿里云的环境检测系统设计
Asp.net MVC中文件夹中的控制器如何跳转到根目录的控制器中?
Ma Zhixing entered the mass production of front loading, starting with the self-developed domain controller?
Pointer constant and constant pointer
flink-sql 如何设置 sql执行超时时间
[deep learning CPU (part outside) - virtual memory]
Fuzzy query of SQL
路由 知识
Safari's compatibility with Z-index
【深度学习CPU(番外篇)——虚拟内存】
“蔚来杯“2022牛客暑期多校训练营2 H
Fu Yingna: Yuan universe is the new generation of Internet!
“蔚来杯“2022牛客暑期多校训练营1 J Serval and Essay(启发式合并)
Communication between parent-child components and parent-child components provide and inject
Change the value of the argument by address through malloc and pointer