Welcome Guest, Not a member yet? Register   Sign In
CI can't reuse redis connections
#1

I have a website built using CI, in which I use redis to store session data.

However, when the server frequently queries the session, there will be a lot of "TIME_WAIT" TCP connections. Then redis can not be connected. (Seems that the server is down.)

It seems that use socket instead of TCP could solve the problem. But I found that CI plans to support socket in version 3.1.0, which hasn't been released.

Besides switching to socket, are there any solution to this problem?
Reply
#2

What connection is there to reuse? What do you mean by that? I don't really understand the problem that you're claiming to have.
Reply
#3

(03-07-2016, 10:51 AM)Narf Wrote: What connection is there to reuse? What do you mean by that? I don't really understand the problem that you're claiming to have.

I mean to reuse the connection that CI has already established to redis server.
Reply
#4

The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.
Reply
#5

(03-08-2016, 03:14 AM)roastduck Wrote: The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.

You're not supposed to close and then re-start a session from within the same request.
Reply
#6

(03-08-2016, 04:05 AM)Narf Wrote:
(03-08-2016, 03:14 AM)roastduck Wrote: The problem is that we have to use `session_write_close` to temporarily release the session lock, and re-open it later, to optimize our application. (Actually it does work) But it causes a great number of short TCP connections to redis, which causes a lot of `TIME_WAIT` status and make Redis unable to connect.

Calling `session_write_close` seems the only way to release the lock. I can't simply release the lock but keep the TCP connection. If I can do keep it, that is what "reuse redis connection" means, I can avoid the problem, but I simply unable to do that. Another approach is to use UNIX socket instead of TCP, but it's Codeigniter's future feature and have not been released now.

You're not supposed to close and then re-start a session from within the same request.

But consider the application below: I have a long poll, which keeps checking current status, such as if the user has a new mail, etc. It checks the session every 6 seconds. I have to release the lock just to let other threads able to use session.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB