phpsocketsredishigh-traffic

High traffic connection between Php and Redis


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?


Solution

  • 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.