1. Background description: Using Swoole as TCPServer, configure Worker_num = 8, Task_worker_num = 8. That is, there will be 16 processes. A redid connection is created that reads the Redis saved value in the Ontask (8 task, each task will callback Ontask method) method.
2. Problem Description: Now found error uncaught exception ' redisexception ' with message ' read error on connection '. Preliminary decision is caused by multiple process calls Redid, I only use a task, there is no problem. See the documentation for Swoole:
A Redis connection needs to be established in the Onworkerstart, so there are 8 work and task, and if so there will be 16 Redis connections (task, work start will call Onworkerstart function).
1) need to establish 16 redis connections, I understand that right? How to improve it? 2) Do I have to save each Redis connection? This is not a bit of trouble to use. 3) If I later work, task value increase, will not have more redis connection, what should I do? 4) is not the way I use the problem, then how can I use it?
Reply content:
1. Background description: Using Swoole as TCPServer, configure Worker_num = 8, Task_worker_num = 8. That is, there will be 16 processes. A redid connection is created that reads the Redis saved value in the Ontask (8 task, each task will callback Ontask method) method.
2. Problem Description: Now found error uncaught exception ' redisexception ' with message ' read error on connection '. Preliminary decision is caused by multiple process calls Redid, I only use a task, there is no problem. See the documentation for Swoole:
A Redis connection needs to be established in the Onworkerstart, so there are 8 work and task, and if so there will be 16 Redis connections (task, work start will call Onworkerstart function).
1) need to establish 16 redis connections, I understand that right? How to improve it? 2) Do I have to save each Redis connection? This is not a bit of trouble to use. 3) If I later work, task value increase, will not have more redis connection, what should I do? 4) is not the way I use the problem, then how can I use it?
Yes, each process creates a connection. If you start 200 processes, you will need 200 connections. You're using the right way.
The use of this will indeed create 16 connections. If you do not want to save the connection, you can create a connection when using Redis and use the Pconnect method. Because Redis connections from different processes cannot be shared, there will be more redis as the number of processes increases
The primary logic can be written in the worker process. Part of the Redis operation is encapsulated as a task, executed by a task process. When starting a task, use the Taskwait method to wait for the task to return. This is equivalent to treating the task process as a connection pool.
If there are other slow tasks that require task asynchronous processing, you can pass in the specified Workerid when the task is started, which is to distinguish the task process from the one that is responsible for redis data processing and some for slow tasks.
1:redis and MySQL mechanism are not the same, not afraid to connect more. 2: No need to use pconnect, Swoole itself is a long-standing memory, after connect, unless the worker restarts, the connection is not valid. 3:read error on connection, you can only reuse the same connection, but this connection may be close in other processes.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.