Redis优化系列:连接数优化

网友投稿 738 2022-09-26

Redis优化系列:连接数优化

Redis优化系列:连接数优化

笔者最近在使用Protostuff优化redis缓存部分,为了前后对比使用内存变化,于是使用期了命令。

1、登录服务器

/usr/bin/redis-cli -p 6379

2、查看内存

info memory

其中used_memory是使用的内存,used_memory_human是便于阅读的数值(human参数类似于linux的h参数,方便人机阅读)。

当然用info命令也可以查看所有参数

127.0.0.1:9543> info# Serverredis_version:3.2.12redis_git_sha1:00000000redis_git_dirty:0redis_build_id:7897e7d0e13773fredis_mode:standaloneos:Linux 4.19.0-6.el7.ucloud.x86_64 x86_64arch_bits:64multiplexing_api:epollgcc_version:4.8.5process_id:53065run_id:9647503ba308d70c662154fd1f874fca2d7f861etcp_port:9543uptime_in_seconds:4241299uptime_in_days:49hz:10lru_clock:16335376executable:/usr/bin/redis-serverconfig_file:/etc/redis.conf# Clientsconnected_clients:51client_longest_output_list:0client_biggest_input_buf:0blocked_clients:0# Memoryused_memory:2552592used_memory_human:2.43Mused_memory_rss:9994240used_memory_rss_human:9.53Mused_memory_peak:2957584used_memory_peak_human:2.82Mtotal_system_memory:1919422464total_system_memory_human:1.79Gused_memory_lua:37888used_memory_lua_human:37.00Kmaxmemory:0maxmemory_human:0Bmaxmemory_policy:noevictionmem_fragmentation_ratio:3.92mem_allocator:jemalloc-3.6.0# Persistenceloading:0rdb_changes_since_last_save:6rdb_bgsave_in_progress:0rdb_last_save_time:1610170433rdb_last_bgsave_status:okrdb_last_bgsave_time_sec:0rdb_current_bgsave_time_sec:-1aof_enabled:0aof_rewrite_in_progress:0aof_rewrite_scheduled:0aof_last_rewrite_time_sec:-1aof_current_rewrite_time_sec:-1aof_last_bgrewrite_status:okaof_last_write_status:ok# Statstotal_connections_received:1156total_commands_processed:44870instantaneous_ops_per_sec:0total_net_input_bytes:28006092total_net_output_bytes:134623051instantaneous_input_kbps:0.00instantaneous_output_kbps:0.00rejected_connections:0sync_full:0sync_partial_ok:0sync_partial_err:0expired_keys:3evicted_keys:0keyspace_hits:11414keyspace_misses:1111pubsub_channels:0pubsub_patterns:1latest_fork_usec:606migrate_cached_sockets:0# Replicationrole:masterconnected_slaves:0master_repl_offset:0repl_backlog_active:0repl_backlog_size:1048576repl_backlog_first_byte_offset:0repl_backlog_histlen:0# CPUused_cpu_sys:2169.39used_cpu_user:1198.49used_cpu_sys_children:0.28used_cpu_user_children:0.33# Clustercluster_enabled:0# Keyspacedb0:keys=52,expires=0,avg_ttl=0

就在笔者使用这个命令列举运行时状态信息后,发现connected_clients参数非常大,这台redis是外网的服务器。发现51个连接。

使用同样程序在内网跑,连接数只有15个,相差较多。按照网上进行优化

1、查看连接超时(0代表不超时)

config get timeout

2、设置超时参数

config set timeout 1000

永久生效办法,修改配置文件

vim /etc/redis.conf

修改timeout为1000

再次查询只有3个连接

参考:Redis连接的客户端(connected_clients)数过高或者不减的问题解决方案

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:centos7启动SonarQube 8.6报错
下一篇:catalina-daemon.out文件太大
相关文章

 发表评论

暂时没有评论,来抢沙发吧~