1. background description: Swoole is used as the TcpServer, and worker_num8 and task_worker_num8 are configured. that is, there will be 16 processes. A redid connection is created to read the value saved by redis in the onTask (8 tasks, each of which calls back the onTask method) method. 2. ask...
1. background description: Swoole is used as the TcpServer, and worker_num = 8 and task_worker_num = 8 are configured. that is, there will be 16 processes. A redid connection is created to read the value saved by redis in the onTask (8 tasks, each of which calls back the onTask method) method.
2. problem description: the following error occurs: Uncaught exception 'redisexception' with message 'read error on connection '. It is preliminarily determined that multiple processes call redid. I only use one task, and there is no problem.
See swoole's document:
To establish a redis connection in onWorkerStart, there are 8 work and task nodes each. if so, there will be 16 redis connections (the onWorkerStart function will be called during task and work startup ).
1) We need to establish 16 redis connections. is that correct for me? How can we improve it?
2) Do I need to save every redis connection? It's not easy to use.
3) If the number of work and task increases in the future, wouldn't there be more redis connections? what should I do?
4) Is there a problem with how I use it? how can I use it?
Reply content:
1. background description: Swoole is used as the TcpServer, and worker_num = 8 and task_worker_num = 8 are configured. that is, there will be 16 processes. A redid connection is created to read the value saved by redis in the onTask (8 tasks, each of which calls back the onTask method) method.
2. problem description: the following error occurs: Uncaught exception 'redisexception' with message 'read error on connection '. It is preliminarily determined that multiple processes call redid. I only use one task, and there is no problem.
See swoole's document:
To establish a redis connection in onWorkerStart, there are 8 work and task nodes each. if so, there will be 16 redis connections (the onWorkerStart function will be called during task and work startup ).
1) We need to establish 16 redis connections. is that correct for me? How can we improve it?
2) Do I need to save every redis connection? It's not easy to use.
3) If the number of work and task increases in the future, wouldn't there be more redis connections? what should I do?
4) Is there a problem with how I use it? how can I use it?
Yes. each process creates a connection. If 200 processes are started, 200 connections are required. Your usage is correct.
In this way, 16 connections are indeed created.
If you do not want to save the connection, you can create a connection when using redis, using pconnect.
Because redis connections of different processes cannot be shared, there will be more redis connections as the number of processes increases.
You can write the main logic in the worker process. Redis operations are encapsulated into tasks and executed by the task process. When starting a task, use the taskwait method to wait for the task to return. In this way, the task process is treated as a connection pool.
If other slow tasks require asynchronous processing of tasks, you can input the specified workerid when starting the task. in this way, the task process is distinguished, and some are responsible for redis data processing, some are responsible for slow tasks.
1: redis and mysql have different mechanisms and are not afraid of many connections.
2: pconnect is not necessary. swoole itself is long in memory. after connect, the connection fails unless the worker restarts.
3: read error on connection. you can only reuse the same connection, but the connection may be closed in other processes.