Redis multi-process Uncaughtexception 'redisexception' withmessage

Source: Internet
Author: User
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.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.