我有一个简单的网络场景,用于在一台机器上使用 lnmp 和 redis 存储客户端-服务器 mac 地址,我使用的 api 非常简单,如下所示:
$db->set($client_key, $client_mac);
$db->expire($client_key , 24 * 3600);
但是当负载很高时(我的 php-fpm 动态模式分叉了大约 400 个子进程来处理 web 请求),我发现 php-fpms 正在等待 redis-server 所以整个性能非常低,我不知道如何解决这个问题,如果可以的话,请帮助我。
你可以看到延迟非常高:redis-cli --latency
min: 142, max: 535, avg: 303.74 (66 samples)
当我试图停止我的 lnmp 时,延迟下降得非常快。
min: 0, max: 136, avg: 16.52 (860 samples)
我认为我的内在延迟还可以: redis-cli --intrinsic-latency 100
499179439 total runs (avg latency: 0.2003 microseconds / 200.33 nanoseconds per run).
127.0.0.1:6379> 慢日志获取
1) 1) (integer) 154
2) (integer) 1513766672
3) (integer) 21172
4) 1) "SET"
2) "AP_9whiJGOV3OiNVLp0hjjNSy9E"
3) "A4:FB:8D:C3:D8:CD"
2) 1) (integer) 153
2) (integer) 1513766660
3) (integer) 18045
4) 1) "GET"
2) "CLIENT_cvsgpu88Q4eO5CTF5ybUNJhe"
3) 1) (integer) 152
2) (integer) 1513766647
3) (integer) 20028
4) 1) "EXPIRE"
2) "CLIENT_4gHpr4aHxmILzTELJK0Dcv79"
3) "86400"
4) 1) (integer) 151
2) (integer) 1513766624
3) (integer) 12845
4) 1) "EXPIRE"
2) "CLIENT_w1W9gWEyPTzCdEXTeIlw5Asr"
3) "86400"
5) 1) (integer) 150
2) (integer) 1513766570
3) (integer) 24071
4) 1) "GET"
2) "AP_wRcMSNBEsqW9zLesFaXInhiN"
免费-g
total used free shared buff/cache available
Mem: 31 4 11 0 15 25
Swap: 15 0 15
127.0.0.1:6379> 信息
# Server
redis_version:3.2.0
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:73889ba3761658f4
redis_mode:standalone
os:Linux 3.10.0-514.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:14995
run_id:eeec40fcb1e95159d255e77f2f5ef2c27347ff0c
tcp_port:6389
uptime_in_seconds:5496
uptime_in_days:0
hz:10
lru_clock:3820557
executable:/usr/local/redis/bin/redis-server
config_file:/usr/local/redis/etc/redis.conf
# Clients
connected_clients:409
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
# Memory
used_memory:367481976
used_memory_human:350.46M
used_memory_rss:372391936
used_memory_rss_human:355.14M
used_memory_peak:370264560
used_memory_peak_human:353.11M
total_system_memory:33555197952
total_system_memory_human:31.25G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.01
mem_allocator:jemalloc-4.0.3
# Persistence
loading:0
rdb_changes_since_last_save:4107050
rdb_bgsave_in_progress:0
rdb_last_save_time:1513764501
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
# Stats
total_connections_received:1275448
total_commands_processed:6172596
instantaneous_ops_per_sec:1116
total_net_input_bytes:372869112
total_net_output_bytes:44716089
instantaneous_input_kbps:65.61
instantaneous_output_kbps:8.22
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:496919
keyspace_misses:293242
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0
# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:394.97
used_cpu_user:130.14
used_cpu_sys_children:0.00
used_cpu_user_children:0.00
我检查的一些文档建议缩短密钥并选择其他 api,我还没有尝试过,你怎么看?