当前位置:网站首页>Swoole collaboration
Swoole collaboration
2022-07-28 01:11:00 【Life goes on and battles go on】
Introduce
from 4.0 Version start Swoole Provided complete coroutines (Coroutine)+ passageway (Channel) characteristic , Bring new CSP Programming model .
- Developers can write code in a synchronous way without perception asynchronous IO The effect and performance of , It avoids the discrete code logic brought by the traditional asynchronous callback and the code cannot be maintained due to multi-layer callback
- At the same time, because the bottom layer encapsulates the collaborative process , So compared with the traditional
PHPLayer collaboration framework , Developers don't need to use yield Keywords to identify a collaborative processIOoperation , So there's no need to talk aboutyieldIn-depth understanding of the semantics of and the calls to each level are modified toyield, This greatly improves development efficiency - Various types of perfect Process client , It can meet the needs of most developers .
A coroutine can be simply understood as a thread , It's just that this thread is user mode , No operating system involvement required , Very low cost to create destroy and switch , Unlike threads, coroutines cannot take advantage of multiple cores cpu Of , Want to use multi-core cpu Need to rely on Swoole The multi process model of .
What is? channel
channel It can be understood as message queue , It's just a message queue between processes , Multiple processes pass push and pop Operate production messages and consumption messages , Used for communication between processes . It should be noted that channel There is no way to cross process , Only one Swoole Communication between processes , The most typical application is Connection pool and Concurrent invocations .
What is a process container
Use Coroutine::create or go Method to create a coroutine ( Reference resources Alias section ), Only in the created collaboration can we use the collaboration API, And the process must be created in the process container , Reference resources The coroutine container .
Scheduling
Here we will try to talk about what is collaborative scheduling , First of all, each coroutine can be simply understood as a thread , As we all know, multithreading is to improve the concurrency of programs , The same multi concurrency is also to improve concurrency .
Each request of the user will create a collaboration , After the request, the collaboration ends , If there are thousands of concurrent requests at the same time , There will be thousands of processes in a process at a certain time , that CPU Resources are limited , Which collaboration code is executed ?
Decide whether to let CPU The code decision process of executing which collaboration is Scheduling ,Swoole What is the scheduling strategy of ?
First , I found that this line of code encountered
Co::sleep()Or networkIO, for exampleMySQL->query(), This must be a time-consuming process ,SwooleIt will Mysql Connected Fd Put it in EventLoop in .- And then give up this process CPU For other processes : namely
yield( Hang up ) - wait for MySQL After the data is returned, continue to execute this process : namely
resume( recovery )
- And then give up this process CPU For other processes : namely
secondly , If the code of the collaboration has CPU Intensive code , Can be opened enable_preemptive_scheduler,Swoole Will forcibly let this process yield CPU.
边栏推荐
- c# 反射之Type使用
- Un7.13: how to add, delete, modify and query in vs Code?
- Resolved Unicode decodeerror: 'UTF-8' codec can't decode byte 0xa1 in position 0: invalid start byte
- Border width border fillet border color
- C语言程序设计 | 单身狗题目讲解
- Vandermond convolution learning notes
- Recommended system - fine tuning model: xdeepfm
- 为华为打造无美系设备的产线,台积电三星能做到吗?
- SRv6初登场
- Jerry caused other messages to accumulate in the message pool [article]
猜你喜欢
随机推荐
Swoole内存-table详解
Matlab 绘制 - 点和向量:向量加减的方法和源码
Srv6 debut
Ford SUV "Mustang" officially went offline, safe and comfortable
《KMP复习 + AC自动机》前传
Storage of deep planing data in memory
深度刨析数据在内存中的存储
C language programming | single dog topic explanation
[300 opencv routines] 241. Scale invariant feature transformation (SIFT)
Sign up now | cloud native technology exchange meetup Guangzhou station has been opened, and I will meet you on August 6!
Jmeter在性能测试中的应用实践样例
Focal Loss讲解
Recommended system - fine tuning model: xdeepfm
Six relationships of UML class diagram, the best way to learn and understand
C语言程序设计 | 单身狗题目讲解
Multithreading and multithreaded programming
Jerry's Bluetooth can only link back to the last device [article]
Operators in MySQL
"C language" deep entry rounding & four functions
At least 42 employees are infected with novel coronavirus! Nokia announces closure of telecom equipment plant in India




![Jerry's prompt sound processing when switching devices [chapter]](/img/b3/38f55143b5ca8c3b2059c5f6f1da37.png)




