最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Redis with php in docker connection failing after 15k requests when doing load test - Stack Overflow

programmeradmin1浏览0评论

I am working on a docker application with php,mysql,redis. The application is such that individual requests hit a php url, which opens a redis connection, reads/ updates key, and closes connection. I have it working, but when i use k6 for a load test, I start getting " Uncaught RedisException: Cannot assign requested address" error, after about 15k requests. I tried using twemproxy, but this does not seem to make a difference. Looking for some help with what I might be doing wrong.

Dockerfile:

FROM unit:1.34.1-php8.4


ENV PHP_OPCACHE_VALIDATE_TIMESTAMPS="0" \
    PHP_OPCACHE_MAX_ACCELERATED_FILES="10000" \
    PHP_OPCACHE_MEMORY_CONSUMPTION="192" \
    PHP_OPCACHE_MAX_WASTED_PERCENTAGE="10"
    
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli

...handle opcache, supervisor, other dependencies, etc...

EXPOSE 80 

# Start supervisord which will manage both cron and nginx unit
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"]

Docker-compose.yml (before adding twemproxy)

services:
  php:
    build:
      context: .
      dockerfile: Dockerfile
    working_dir: /var/www/html/
    container_name: phpApp
    ports:
      - '80:80'
    volumes:
      - '.:/var/www/html/'
    depends_on:
      - mysql_db
      #- twemproxy  # Add dependency to twemproxy if using twemproxy
      - redis  # Add dependency to redis
    networks:
      - default 
  redis:
    container_name: redis
    image: 'redis:alpine3.21'
    ports:
      - '6379:6379'
    networks:
      - default

And for twemproxy, I used a separate dockerfile, and the following in docker-compose

twemproxy:
    build:
      context: .
      dockerfile: Dockerfile.twemproxy  # Build Twemproxy from the Dockerfile
    container_name: twemproxy
    ports:
      - '6380:6379'  # Expose the same port that Redis would have exposed
    volumes:
      - ./config/twemproxy.yml:/etc/twemproxy/nutcracker.yml  # Twemproxy config file
    depends_on:
      - redis  # Ensure Redis is available before Twemproxy starts
    networks:
      - default

And the following conf

alpha:
  listen: 0.0.0.0:6380
  hash: fnv1a_64
  distribution: ketama
  redis: true
  auto_eject_hosts: true
  server_retry_timeout: 2000
  server_failure_limit: 3
  servers:
    - redis:6379:1

target.php file. This is what is being hit in the load test.

<?php 

$redis = new Redis(); 
$redis->connect('redis', 6379,1);
//$redis->connect('twemproxy', 6380); //When  using Twemproxy

if($redis->exists($serial)){
  //Do stuff
}
$redis->close();
?>

When testing with K6, the script is set to make ~500 to 800 connections per second. The test keeps going, and once it hits around 14-15k hits, redis seems to stop responding. And In docker stats, I can see that redis cpu usage goes from ~30% when running fine, to 0 when it stops.

NOTE I came across this. I am not sure if this makes redis not usable in my case, as given the application, my use case is going to be a lot of requests needing to be serviced.

发布评论

评论列表(0)

  1. 暂无评论