当前位置:网站首页>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.
边栏推荐
- 进程与进程调度
- 计算属性的基本使用
- Un7.13: how to add, delete, modify and query in vs Code?
- Recommend a Hongmeng instant messaging software "fruit chat", which is a bit awesome!!
- Ink wheel salon | Li Wenjie, Peking University: a graph database system for knowledge atlas application gstore
- Ford SUV "Mustang" officially went offline, safe and comfortable
- Can TSMC Samsung build a production line without American equipment for Huawei?
- Postman download and use tutorial
- 激活最大化
- Postman下载、使用教程
猜你喜欢
随机推荐
Border width border fillet border color
Multithreading & high concurrency (the latest in the whole network: interview questions + map + Notes) the interviewer is calm
接口测试实战项目02:读懂接口测试文档,上手操练
Focal Loss讲解
uniapp显示富文本效果demo(整理)
推荐系统-模型:dssm双塔模型做embedding的召回
SAP各模块优缺点和发展简析
Jerry Zhi has problems in real-time adjustment of sound change effect in magic sound mode [chapter]
Database daily question --- day 22: last login
小波变换学习笔记
分支和循环语句题目练习
Process and process scheduling
C语言程序设计 | offsetof宏的讲解及其模拟实现
一周年创作纪念日,冲吧少年郎
7. Typescript part Foundation
[proteus simulation] 51 single chip microcomputer washing machine simulation control program
字节飞书人力资源套件三面
IP address & subnet mask
Resolved Unicode decodeerror: 'UTF-8' codec can't decode byte 0xa1 in position 0: invalid start byte
线性代数 【23】 概念的深入01 - Points坐标点和Vectors向量









