zoukankan      html  css  js  c++  java
  • Redis性能优化之redis.cnf配置参数

    redis调优总结

    1、相应的参数调优 加内存
    2、redis使用结构调优
    3、使用合理的数据类型
    说明:redis存储的数据为redis hash(字符映射表) 单key多字段结构。

    1)调整配置文件中配置项的值(修改文件:redis.conf)
    1)调整memory大小 redis.conf 中maxmemory 不需要配置(作为数据库来使用) 需要配置(作为缓存来使用)
    2)设置过期时间 expires 键值名称 秒数 expires key 60 设置过期时间 为了腾出更多的空间

    过期策略:
    没有设置key的过期时间,则使用 allkeys-lru lru算法
    有设置key的过期时间,则使用 volatile-ttl ttl算法

    3)设置redis允许处理的最大请求连接数,减少延迟时间
    调整maxclients大小 为监控得出的数据1~1.5倍

    4)其他参数
    超过多少秒后,关闭空闲连接 TCP keepalive
    关闭检查数据库数据的正确性 rdbchecksum off

    5)调整持久化在线重写方式
    auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-rewrite-incremental-fsync yes
    max-size*max-total <硬盘大小

    auto-aof-rewrite-percentage
    auto-aof-rewrite-min-size
    auto-aof-incremental-fsync yes

    6)加大内存的大小,避免未知错误
    overcommit_memory文件指定了内核针对内存分配的策略,其值可以是0、1、2。
    0, 表示内核将检查是否有足够的可用内存供应用进程使用;如果有足够的可用内存,内存申请允许;否则,内存申请失败,并把错误返回给应用进程。
    1, 表示内核允许分配所有的物理内存,而不管当前的内存状态如何。
    2, 表示内核允许分配超过所有物理内存和交换空间总和的内存
    more /proc/sys/vm/overcommit_memory
    vm.overcommit_memory=1

    6)redis慢查询日志,单位微秒
    redis配置中进行,
    slowlog-log-slower-than 10000 (负数:禁用慢查询,0:记录执行命令,正数:大于该值则记录执行命令)
    slowlog-max-len 128 保持最新条数的慢查询日志

    7)时间单位
    秒(s)->毫秒(ms)->微秒(μs)->纳秒(ns)


    redis命令 info
    "# Server
    redis_version:3.2.8
    redis_git_sha1:00000000
    redis_git_dirty:0
    redis_build_id:39d8556c0694236f
    redis_mode:standalone
    os:Linux 2.6.32-431.el6.x86_64 x86_64
    arch_bits:64
    multiplexing_api:epoll
    gcc_version:4.4.7
    process_id:1863
    run_id:ca9be02eda4d76e24fae00d38eadb901cafc8a2d
    tcp_port:6379
    uptime_in_seconds:7744909
    uptime_in_days:89
    hz:10
    lru_clock:9071420
    executable:/usr/local/bin/redis-server
    config_file:/etc/redis/6379.conf

    # Clients
    connected_clients:2
    client_longest_output_list:0
    client_biggest_input_buf:0
    blocked_clients:0

    # Memory
    used_memory:2629176
    used_memory_human:2.51M
    used_memory_rss:15454208
    used_memory_rss_human:14.74M
    used_memory_peak:4687293024
    used_memory_peak_human:4.37G
    total_system_memory:8238727168
    total_system_memory_human:7.67G
    used_memory_lua:37888
    used_memory_lua_human:37.00K
    maxmemory:0
    maxmemory_human:0B
    maxmemory_policy:noeviction
    mem_fragmentation_ratio:5.88
    mem_allocator:jemalloc-4.0.3

    # Persistence
    loading:0
    rdb_changes_since_last_save:0
    rdb_bgsave_in_progress:0
    rdb_last_save_time:1502204630
    rdb_last_bgsave_status:ok
    rdb_last_bgsave_time_sec:0
    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:405913
    total_commands_processed:13174626
    instantaneous_ops_per_sec:0
    total_net_input_bytes:11389773051
    total_net_output_bytes:27637853903
    instantaneous_input_kbps:0.00
    instantaneous_output_kbps:0.00
    rejected_connections:0
    sync_full:0
    sync_partial_ok:0
    sync_partial_err:0
    expired_keys:281598
    evicted_keys:0
    keyspace_hits:3651658
    keyspace_misses:583361
    pubsub_channels:0
    pubsub_patterns:0
    latest_fork_usec:887
    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:1399.92
    used_cpu_user:1629.98
    used_cpu_sys_children:59.56
    used_cpu_user_children:129.99

    # Cluster
    cluster_enabled:0

    # Keyspace
    db0:keys=1078,expires=15,avg_ttl=52686270
    db14:keys=1,expires=0,avg_ttl=0

  • 相关阅读:
    了解 NoSQL 的必读资料
    关于什么时候用assert(断言)的思考
    这次见到了一些大侠
    NetBeans 时事通讯(刊号 # 87 Jan 12, 2010)
    动态链接库dll,静态链接库lib, 导入库lib
    新女性十得 写得了代码,查得出异常
    记录系统乱谈
    新女性十得 写得了代码,查得出异常
    fullpage.js禁止滚动
    RunningMapReduceExampleTFIDF hadoopclusternet This document describes how to run the TFIDF MapReduce example against ascii books. This project is for those who wants to experiment hadoop as a skunkworks in a small cluster (110 nodes) Google Pro
  • 原文地址:https://www.cnblogs.com/NiceTime/p/7640611.html
Copyright © 2011-2022 走看看