当前位置:网站首页>Swoole high performance in memory database use and configuration tutorial
Swoole high performance in memory database use and configuration tutorial
2022-04-22 10:12:00 【CRMEB】
Usage environment :thinkphp6.* + think-swoolev4.0
explain
because PHP The language does not support multithreading , therefore Swoole Use multiprocess mode , There is process memory isolation in multi process mode , Modify... In the course of work global Global variables and super global variables , Invalid in other processes .
The corresponding solutions are :
- Use Redis database 、 Relational database Mysql
- Memory files /dev/shm
First of all, the operation of the database involves IOD Waiting time , Therefore, it is recommended to use Table
Attribute specification
size Get the maximum number of rows in the table
Swoole\Table->size;
memorySize
Get the size of the actual memory used , The unit is byte
You can use the property to get the current occupied memory , It is conducive to adjusting the configuration . Avoid appearing :Unable to allocate memory error
Swoole\Table->memorySize;
To configure
file location :config/swoole.php
return [
'tables' => [
// High performance in memory database
'user' => [
'size' => 20480, // Specify the database memory size
'columns' => [
['name' => 'fd', 'type' => Table::TYPE_INT],// Built in fields , Set it up by yourself
['name' => 'type', 'type' => Table::TYPE_INT],
['name' => 'uid', 'type' => Table::TYPE_INT,'size'=>1024],
['name' => 'to_uid', 'type' => Table::TYPE_INT],
['name' => 'tourist', 'type' => Table::TYPE_INT]
]
]
],
];
The above configuration... Needs to be added to the configuration file :user Is the name of the watch ,size Is the database size ,columns For database fields
You can add multiple databases
matters needing attention :
size The generation size of needs to be determined according to its own use , Too small to expand automatically . Need to restart service .
To modify the memory database, you must restart swoole To take effect
Use scenarios
- socket Communication records fd Binding relationship with users
- Read record data globally as a cache
- It can be used as a counter , Atomic level . There will be no problem of concurrency. How to use... In the framework
use think\swoole\Table;
use Swoole\Table as SwooleTable;
// Get the instantiated table object
$make = app()->make(Table::class);
// obtain user Example
[ Add link description ](https://q.crmeb.com)/** @var SwooleTable $table **/
$table = $make->get('user');
// Set up the data
$table->set('1',['fd'=>123,'type'=>1,'uid'=>1,'to_uid'=>0,'tourist'=>0]);
// Read key=1 The data of
$table->get('1');
foreach ($table as $key => $value) {
var_dump($key);// Set up key
var_dump($value);// Set up value data
}
Last
If you think this article is useful to you , Please give our open source project a little bit star:http://github.crmeb.net/u/defu Thank you for !
Get the source code address for free :http://www.crmeb.com
PHP Learning manual :https://doc.crmeb.com
Technical exchange forum :https://q.crmeb.com
版权声明
本文为[CRMEB]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220958304621.html
边栏推荐
- 作文以记之 ~ 目标和
- The headline interview actually told me about semaphore for half an hour
- Unity3D build时错误提示:Missing Project ID in Unity 解决方案
- You need to specify one of MySQL_ ROOT_ PASSWORD, MYSQL_ ALLOW_ EMPTY_ PASSWORD and MYSQ
- *CTF 2022 Reverse Writeup
- Review of QT layout management
- Ukui3 supports openeuler 22.03 LTS
- HAS2022 | 第19届华为全球分析师大会即将启幕!
- SQL 创建数据库
- 三分钟快速了解互动涂鸦
猜你喜欢

通过LayerDrawable实现进度条的功能

P8 data broadcasting

Writing to remember the ~ goal and

头条面试居然跟我扯了半小时的Semaphore

The VirtualBox virtual machine uses virtio net to run dpdk + VPP and cannot receive VLAN messages

Leapftp: 425 failed to establish connection solution

Depth first search (I): middle order traversal of binary tree (force buckle)

Command ‘yum‘ not found, but can be installed with: apt install yum

Multi target tracking extended Kalman filter (EKF)

Beyond iterm! Known as the next generation terminal artifact, powerful!
随机推荐
SWOOLE高性能内存数据库的使用和配置教程
[C language advanced level 10 -- character and string functions and their simulation implementation (1)]
作文以记之 ~ 目标和
DPU 芯片头部企业云豹智能加入 openEuler社区,为数字中国基础设施助力
The web application scans the code to obtain the user information of zhezheng nail
Summary of JS page refresh methods
OGG-00663 OCI Error ORA-02396: exceeded maximum idle time
Cross platform compilation
tensorflow实验四----波士顿房价预测
Oracle 11.0 under Windows Upgrade from 2.0.1 to Oracle 11.0 2.0.4
Glide设置圆角图片(支持自定义圆角位置)
Meituan side: have you used jstat, jmap, mat in the production time? Can you give me a practical example?
Review of QT layout management
source_ Insight is a method to create a new project and search for a variable or function in the whole document
The headline interview actually told me about semaphore for half an hour
【HLS】可变帧率和固定帧率拉流
【QT小记】使用QPainter绘制各种基本图形
Windows下oracle11.2.0.1升级至oracle11.2.0.4
DA14580BLE点亮LED
中国电信CTyunOS规模部署,携手openEuler共筑天翼云数字底座