0

I have backend on php, that works with Redis.

But when requests increased and they more than 2000 request per sec I receive an error:

99 - Cannot assign requested address

All sockets in TIME_WAIT.


Connecting example:

$this->_socket = @stream_socket_client(
    'tcp://' . $this->hostname . ':' . $this->port,
    $errorNumber,
    $errorDescription,
    ini_get('default_socket_timeout'),
    STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT
);

I find solution: http://redis4you.com/articles.php?id=012&name=redis

But /proc/sys/net/ipv4/tcp_tw_recycle I can't set in 1. Don't want to loss packets on the network between application and redis.

Php on new request from API create a new socket.

Any ideas?

SiJey
  • 169
  • 1
  • 4
  • 9

2 Answers2

0

I don't know your whole design, but here something you could do :

  • Create a PHP page that always run (with a while(true) loop)
  • This page would wait for content from your initial page (where the socket code was before)
  • Using the pipelining technique, you would send all requests using the same socket.
  • Only thing missing is how to pass data from the initial page to this new page.

For that last part I see multiple solutions (not sure if they all work though) :

  • Using APC to store data from initial page and still use it to get it from the new one.
  • Create a SESSION in the new page which would than have two modes : Processing, Submitting. You should then call this page using your local server inside the initial page.

In both solutions, one instance of this new page shall be executed locally so the 'Processing/Waiting' is activated.

Master DJon
  • 1,899
  • 2
  • 19
  • 30
0

Fixed problem. Use tcp reuce and time waite for socket sets in 10 seconds. Php work with socket in persistent mode

STREAM_CLIENT_CONNECT | STREAM_CLIENT_PERSISTENT

So even in 2 000 request per second it use not more then 61 sockets.

SiJey
  • 169
  • 1
  • 4
  • 9