The introduction of network IO model leads to the network IO model of nginx

Linux server development 2020-11-10 16:01:14
introduction network io model leads


  1. What is? IO?
In short, it's input and output
  1. The Internet IO Go through the steps

  1. Users are getting network resources in the network card , Through the network seven layer model, the request is handed to nginx User process
  2. The user process cannot directly get resources on disk , What resources will be translated and forwarded to the kernel , Kernel driver disk seek find file ( The most time-consuming part )
  3. Files can't be handed over directly to the user process , First, the disk puts the file into the kernel buffer , The kernel then tells the user that the resource results requested by the process are ready ( It takes less time )
  4. The kernel buffer copies a file to the user process buffer , The user process gets the file Build response message , adopt http Back to the user

summary :

IO There are two stages to go through

1. Disk read data , Copy the data to the kernel buffer

2. Copy kernel buffer data to user process buffer


  1. The Internet IO Model type

Synchronous blocking


For example, if you want to complete such a thing , Boil the water , Fill the thermos

Now I'll give you a common pot , You don't know when the water will burn , You decide to stand by and wait for the water to boil .

You can't do anything at this time , Don't you think it's a waste of time

When the water is open, you need to fill the water into the thermos , You still can't do anything else

Synchronous nonblocking


For example, it's still boiling water , You still don't know when the water will open , You chose another strategy , Go busy with other things but watch who can't open it from time to time

What has been improved ?


You can be busy with other things in the neutral

What's the added trouble ?


  1. You have to make sure the water is boiling from time to time ( It means that you have to keep calling cpu, Occupy cpu resources )
  2. Maybe the last time you saw it, the water didn't open , When you just finished watching the water boil , Then it's up to the next time you look at it to find out , Increased delay , When you know, the water is boiling , Go and fill the water yourself

Linuxc/c++ Server development of high-level video learning materials +qun720209036 obtain

image.png


More video content includes C/C++,Linux,Nginx,ZeroMQ,MySQL,Redis,MongoDB,ZK, Streaming media ,P2P,K8S,Docker,TCP/IP, coroutines ,DPDK Multiple advanced knowledge points to share .

Asynchronous blocking


This is a comparison of two

If I give you a smart thermos , When the water boils, it will remind you automatically , But you still have to wait

There is no use of the advantages of intelligent hot water bottles ( Do not explain )

Synchronous asynchronous : Focus on the notification mechanism of messages

Blocking non blocking : The concern is whether the caller's status is waiting or busy before he receives the result

IO Multiplexing


Take the example of boiling water

Don't care if the water is boiling , Give it directly to an agent , If the agent's name is select,select I'll help you monitor whether the water is boiling or not , Take him and see if the meal is cooked , You give it everything , Can go to busy with their own things in the meal is not cooked , When the water is still boiling select In a state of waiting , If the water boils at this time select The result of the meeting water is written on a small blackboard, and you can see and know that the water is on , You don't need to check if the water is boiling , Next, you pour the boiling water into the thermos ( The first half of the user process is not blocked , The second half is blocked )

select、poll、epoll The difference between


Whether it's select、poll、epoll Can face requests from multiple user processes , It's equivalent to an agent , Collect requests from many user processes , He helps you get data from the disk , Copy to the kernel , So it's not the same that the data is not ready for its implementation mechanism

Inform the way : Suppose you have a user data ready , So there are still a lot of user data that are not ready , So how to inform ?

select and poll It's a traversal scan , inefficiency

epoll Using a callback mechanism ,epoll Will inform you , More efficient (nginx Support )

Signal driven IO


give an example : For example, our intelligent hot water kettle I set up after the water is burned , You will be given a feedback result for setting success , And then you can go and do something else , When the water boils, a short message will be sent to you , Then you go back and fill the thermos with water

A notification mechanism : Level trigger : Notice many times Edge trigger : Only once

版权声明
本文为[Linux server development]所创,转载请带上原文链接,感谢

  1. [front end -- JavaScript] knowledge point (IV) -- memory leakage in the project (I)
  2. This mechanism in JS
  3. Vue 3.0 source code learning 1 --- rendering process of components
  4. Learning the realization of canvas and simple drawing
  5. gin里获取http请求过来的参数
  6. vue3的新特性
  7. Get the parameters from HTTP request in gin
  8. New features of vue3
  9. vue-cli 引入腾讯地图(最新 api,rocketmq原理面试
  10. Vue 学习笔记(3,免费Java高级工程师学习资源
  11. Vue 学习笔记(2,Java编程视频教程
  12. Vue cli introduces Tencent maps (the latest API, rocketmq)
  13. Vue learning notes (3, free Java senior engineer learning resources)
  14. Vue learning notes (2, Java programming video tutorial)
  15. 【Vue】—props属性
  16. 【Vue】—创建组件
  17. [Vue] - props attribute
  18. [Vue] - create component
  19. 浅谈vue响应式原理及发布订阅模式和观察者模式
  20. On Vue responsive principle, publish subscribe mode and observer mode
  21. 浅谈vue响应式原理及发布订阅模式和观察者模式
  22. On Vue responsive principle, publish subscribe mode and observer mode
  23. Xiaobai can understand it. It only takes 4 steps to solve the problem of Vue keep alive cache component
  24. Publish, subscribe and observer of design patterns
  25. Summary of common content added in ES6 + (II)
  26. No.8 Vue element admin learning (III) vuex learning and login method analysis
  27. Write a mini webpack project construction tool
  28. Shopping cart (front-end static page preparation)
  29. Introduction to the fluent platform
  30. Webpack5 cache
  31. The difference between drop-down box select option and datalist
  32. CSS review (III)
  33. Node.js学习笔记【七】
  34. Node.js learning notes [VII]
  35. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  36. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  37. 【JQuery框架,Java编程教程视频下载
  38. [jQuery framework, Java programming tutorial video download
  39. Vue Router根据后台数据加载不同的组件(思考->实现->不止于实现)
  40. Vue router loads different components according to background data (thinking - & gt; Implementation - & gt; (more than implementation)
  41. 【Vue,阿里P8大佬亲自教你
  42. 【Vue基础知识总结 5,字节跳动算法工程师面试经验
  43. [Vue, Ali P8 teaches you personally
  44. [Vue basic knowledge summary 5. Interview experience of byte beating Algorithm Engineer
  45. 【问题记录】- 谷歌浏览器 Html生成PDF
  46. [problem record] - PDF generated by Google browser HTML
  47. 【问题记录】- 谷歌浏览器 Html生成PDF
  48. [problem record] - PDF generated by Google browser HTML
  49. 【JavaScript】查漏补缺 —数组中reduce()方法
  50. [JavaScript] leak checking and defect filling - reduce() method in array
  51. 【重识 HTML (3),350道Java面试真题分享
  52. 【重识 HTML (2),Java并发编程必会的多线程你竟然还不会
  53. 【重识 HTML (1),二本Java小菜鸟4面字节跳动被秒成渣渣
  54. [re recognize HTML (3) and share 350 real Java interview questions
  55. [re recognize HTML (2). Multithreading is a must for Java Concurrent Programming. How dare you not
  56. [re recognize HTML (1), two Java rookies' 4-sided bytes beat and become slag in seconds
  57. 【重识 HTML ,nginx面试题阿里
  58. 【重识 HTML (4),ELK原来这么简单
  59. [re recognize HTML, nginx interview questions]
  60. [re recognize HTML (4). Elk is so simple