共计 3676 个字符,预计需要花费 10 分钟才能阅读完成。
明天在测试环境冒烟,发现 redis 报错,JedisDataException: OOM command not allowed when used memory > ‘maxmemory’!
狐疑是写入 redis key 过大导致,于是排查 redis 内存应用状况,应用 INFO 命令,后果如下,
能够看到最大内存为 256M,理论应用曾经 262M,故报错,因为测试服务器没有 redis 客户端,只能通过 DEBUG OBJECT KEY 进行排查,发现是在进行每日下单用户数量统计时,因为用户数量过多,存储的 userId 导致 key 过大,通过理论业务思考 redis 大小配置以及调整代码解决
{
"redis_version": "5.0.5",
"redis_git_sha1": 0,
"redis_git_dirty": 0,
"redis_build_id": "4a12254f65de94f7",
"redis_mode": "standalone",
"os": "Linux 2.6.32-696.el6.x86_64 x86_64",
"arch_bits": 64,
"multiplexing_api": "epoll",
"atomicvar_api": "atomic-builtin",
"gcc_version": "4.8.2",
"process_id": 29941,
"run_id": "9ea1e2e825576ce1510b81ea726bcd3bd6b9806d",
"tcp_port": 6451,
"uptime_in_seconds": 1644062,
"uptime_in_days": 19,
"hz": 10,
"configured_hz": 10,
"lru_clock": 11564232,
"executable": "/usr/local/redis-5.0.5/bin/redis-server",
"config_file": "/data/redis6451/redis-6451.conf",
"connected_clients": 4,
"client_recent_max_input_buffer": 2,
"client_recent_max_output_buffer": 0,
"blocked_clients": 0,
"used_memory": 275653448,
"used_memory_human": "262.88M",
"used_memory_rss": 249323520,
"used_memory_rss_human": "237.77M",
"used_memory_peak": 275775880,
"used_memory_peak_human": "263.00M",
"used_memory_peak_perc": "99.96%",
"used_memory_overhead": 896364,
"used_memory_startup": 791392,
"used_memory_dataset": 274757084,
"used_memory_dataset_perc": "99.96%",
"allocator_allocated": 275688736,
"allocator_active": 276066304,
"allocator_resident": 281153536,
"total_system_memory": 33669332992,
"total_system_memory_human": "31.36G",
"used_memory_lua": 36864,
"used_memory_lua_human": "36.00K",
"used_memory_scripts": 216,
"used_memory_scripts_human": "216B",
"number_of_cached_scripts": 1,
"maxmemory": 268435456,
"maxmemory_human": "256.00M",
"maxmemory_policy": "volatile-lfu",
"allocator_frag_ratio": 1.0,
"allocator_frag_bytes": 377568,
"allocator_rss_ratio": 1.02,
"allocator_rss_bytes": 5087232,
"rss_overhead_ratio": 0.89,
"rss_overhead_bytes": -31830016,
"mem_fragmentation_ratio": 0.9,
"mem_fragmentation_bytes": -26266784,
"mem_not_counted_for_evict": 0,
"mem_replication_backlog": 0,
"mem_clients_slaves": 0,
"mem_clients_normal": 100460,
"mem_aof_buffer": 0,
"mem_allocator": "jemalloc-5.1.0",
"active_defrag_running": 0,
"lazyfree_pending_objects": 0,
"loading": 0,
"rdb_changes_since_last_save": 73047,
"rdb_bgsave_in_progress": 0,
"rdb_last_save_time": 1637310122,
"rdb_last_bgsave_status": "ok",
"rdb_last_bgsave_time_sec": -1,
"rdb_current_bgsave_time_sec": -1,
"rdb_last_cow_size": 0,
"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",
"aof_last_cow_size": 0,
"total_connections_received": 77449,
"total_commands_processed": 230844,
"instantaneous_ops_per_sec": 0,
"total_net_input_bytes": 9262857,
"total_net_output_bytes": 13814796,
"instantaneous_input_kbps": 0.0,
"instantaneous_output_kbps": 0.0,
"rejected_connections": 0,
"sync_full": 0,
"sync_partial_ok": 0,
"sync_partial_err": 0,
"expired_keys": 0,
"expired_stale_perc": 0.0,
"expired_time_cap_reached_count": 0,
"evicted_keys": 0,
"keyspace_hits": 275,
"keyspace_misses": 12,
"pubsub_channels": 0,
"pubsub_patterns": 0,
"latest_fork_usec": 0,
"migrate_cached_sockets": 0,
"slave_expires_tracked_keys": 0,
"active_defrag_hits": 0,
"active_defrag_misses": 0,
"active_defrag_key_hits": 0,
"active_defrag_key_misses": 0,
"role": "master",
"connected_slaves": 0,
"master_replid": "af9620a1329123d2a5ec942f9e78115dcc7c8f72",
"master_replid2": 0,
"master_repl_offset": 0,
"second_repl_offset": -1,
"repl_backlog_active": 0,
"repl_backlog_size": 33554432,
"repl_backlog_first_byte_offset": 0,
"repl_backlog_histlen": 0,
"used_cpu_sys": 460.765952,
"used_cpu_user": 769.999942,
"used_cpu_sys_children": 0.0,
"used_cpu_user_children": 0.0,
"cluster_enabled": 0,
"db0": {
"keys": 81,
"expires": 0,
"avg_ttl": 0
}
}
正文完