Home > PHP Framework > Swoole > body text

Where are swoole used?

(*-*)浩
Release: 2019-12-06 14:10:34
Original
2477 people have browsed it

Where are swoole used?

Introduction to application scenarios

Connect and communicate with hardware devices (positioning devices)

IM system (used for live broadcast pages Chat communication) (Recommended learning: swoole video tutorial)

Scenario 1 - Real-time collection of positioning data and real-time output (for example, Didi driver’s driving trajectory)

Instructions:

Need to receive all positioning devices in real time and display real-time track records on the map

Notes:

First point:

Users 1, 2, 3 connected to the web1 server, web1 can only broadcast users 1, 2, 3, and cannot broadcast web2 when broadcasting information. Connected users 4, 5, 6, assuming the scene is chatting, user 1 sends a message, only users of the web1 server can see it, and all users of web2 cannot receive it

Where are swoole used?

Second point: Frequency control of messages, for example: 100 devices, 100 users, 100 devices upload one piece of data per second, which needs to be broadcast to each user in real time, that is, 100*100 = 1W times per second, so it can Methods such as summarizing data per second and broadcasting to all users

Scenario 2 - only collecting positioning devices into the database

Instructions: It is necessary to enter the data uploaded by all positioning devices Library, 7 devices, one piece of data per second, I personally use swoole's task function (deliver an asynchronous task to the task_worker pool, this function is non-blocking, the number of worker processes can also be configured) and then call the interface to enter the library

Server memory alarm problem

Reason: It lies in the swoole_server->task function

Officially introduces that the bottom layer of task uses Unix Socket pipe communication, which is full memory and has no IO consumption. The read and write performance of a single process can reach 1 million/s. Different processes use different pipelines to communicate, which can maximize the use of multiple cores.

But if the task is to call the program interface, due to network delay, when the added tasks are larger than the consumed tasks, the memory usage will continue to increase, causing the server's memory to be full.

Solution: Control the frequency of messages entering the task. You can define this time and whether it can be delayed according to your own business scenario, summarize all the data within 1 second and then call the program interface (I personally use redis when summarizing ), it is best to store it directly in the database without calling the interface

Scenario-IM system

Refer to the official github: webim system.

Official wiki: swoole framework wiki

Benefits

Encapsulates the model class of the database, the ORM interface of the database

redis encapsulation, can achieve multi-instance access

The framework has some commonly used methods, such as log, etc. (I only used log)

webim has an official demon, you can refer to

The above is the detailed content of Where are swoole used?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!