swoole 彈幕系統

2022-08-26 14:30:26 字數 1652 閱讀 5421

一、伺服器分布

1、lvs負載均衡

2、多台danmu server

3、redis(集群)用於儲存資料和誇伺服器訂閱通知

4、cli server用於讀取快取資料並存到

mysql

,以及清空快取

二、彈幕服務端

1、danmu-server使用

swoole_websocket_server

,中間是子程序,最下面是

redis

伺服器2、web-server是網頁

請求,可以產生的動態推送,並將訊息存到

redis

3、receive-worker-n是

worker

程序3.1、接收使用者發出的訊息,並存到

redis

3.2、在共享記憶體(

data cache

程序)標示該房間有新訊息

4、data-cache-process是

process

程序,用於做共享記憶體,存放

roomid

、fdid

對應關係,房間是否有新訊息標示等等

5、monitor-process是process程序

5.1、分析本機共享記憶體看哪個房間有新訊息(對應

3.2)

5.2、分析

redis

看哪個房間

有新訊息(對應2)

5.3、對有新訊息的

roomid

進行publish

6、send-process-n是

process

程序6.1、啟動時

swoole_redis

去subscribe

6.2、

onmessage

之後讀取訊息,並遍歷傳送給房間內的

fd三、data process程序資料互動

1、worker:

sendmessage

與onpipemessage

2、process:

write

與read

(寫最大

8k,讀最大

64k,自己用

pack

打包)四、特殊說明

1、swoole table需要設定行數,且只支援一維,所以自己用

process

做共享記憶體

2、onhandshake的時候,還處理了分房間、記錄使用者資訊、重新整理新使用者列表、進入房間訊息等

4、部分功能點通過cli指令碼處理,包括

redis

資源入庫及**等

五、**段(暫不提供)

1、server.php

2、coroutine.php

3、data_cache.php

4、packet.php

5、pool.php

swoole 編譯安裝 最新swoole

適用於php5.3以上版本 centos7中 在此 選擇合適的版本,我用的是4.2.9 wget tar zxvf swoole 4.2.9.tgz cd swoole 4.2.9 phpize configure with php config usr local php bin php conf...

Swoole學習 Swoole入門指南

初識swoole swoole官網 swoole官方文件 入門書籍 tcp ip網路程式設計 尹聖雨 韓 深入書籍 unix環境高階程式設計 中文第三版 unix網路程式設計卷1 套接字聯網 unix網路程式設計卷2 程序間通訊 版本已更新至4.3.x。swoole2.0增加協程。swoole3.0...

Swoole 非同步檔案系統IO 讀 寫

非同步io 讀 readfile 有大小限制最大4m read 支援超大檔案讀取 每次分段讀取 size的位元組 不會占用太多記憶體 result swoole async readfile dir 1.txt function filename,filecontent var dump resul...