redis配置注意事項(適合於較大配置)

  根據官方的建議,redis-server的相關配置建議以下,可是有些並不合適,LZ會進行說明(若是redis使用的內存還不到1GB,或者大量qps還不到1000的應用,這已經淘汰了99%的應用,不少配置基本上就無所謂了,基本上沒這麼大影響,保證高可用便可,不會有性能問題的;):html

一、vm.overcommit_memory = 1。實際中最好讓redis主節點僅使用50-60%的內存,剩餘的用於執行bgsave和建立寫命令的緩衝區,保證最大可能的sla。前端

二、禁用linux內核特性transparent huge pages,echo never > /sys/kernel/mm/transparent_hugepage/enabled,oracle也如此要求,TPH和傳統的大頁在機制上有些不一樣,參見http://blog.itpub.net/26736162/viewspace-2214374/。mysql

三、避免使用swap或禁用linux

四、設置maxmemory,限制redis使用的內存數量,而非自動,不然發生交換就奇慢無比了;redis

五、若是是ssd的話,複製模式下建議master節點啓用持久化選項(當超過數GB時,保存快照會對前端影響較大,若是可以容忍極端狀況下小部分更新丟失,應在slave節點機進行,而非master節點,主要多是國外數據沒國內這麼大);sql

六、通常應使用顯示的redis.conf,而非使用內置的配置,可在啓動時經過命令行指定/etc/redis.conf;promise

七、應顯示設置rdb、aof日誌文件目錄及文件名,logfile參數;默認爲工做目錄:架構

# The filename where to dump the DB
dbfilename dump.rdb   # rdb文件名

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.    # rdb存儲目錄
dir ./
[root@XXX redis-3.2.12]# ll | grep dump
-rw-r--r--  1 root root  19274 Aug  8 20:12 dump_16379.rdb
-rw-r--r--  1 root root   1259 Aug  8 22:23 dump_46379.rdb
-rw-r--r--  1 root root 446620 Nov 23 02:05 dump.rdb

 

############################## APPEND ONLY MODE ###############################

# By default Redis asynchronously dumps the dataset on disk. This mode is
# good enough in many applications, but an issue with the Redis process or
# a power outage may result into a few minutes of writes lost (depending on
# the configured save points).
#
# The Append Only File is an alternative persistence mode that provides
# much better durability. For instance using the default data fsync policy
# (see later in the config file) Redis can lose just one second of writes in a
# dramatic event like a server power outage, or a single write if something
# wrong with the Redis process itself happens, but the operating system is
# still running correctly.
#
# AOF and RDB persistence can be enabled at the same time without problems.
# If the AOF is enabled on startup Redis will load the AOF, that is the file
# with the better durability guarantees.
#
# Please check http://redis.io/topics/persistence for more information.

appendonly yes

# The name of the append only file (default: "appendonly.aof")

appendfilename "appendonly.aof"

# The fsync() call tells the Operating System to actually write data on disk
# instead of waiting for more data in the output buffer. Some OS will really flush
# data on disk, some other OS will just try to do it ASAP.
#
# Redis supports three different modes:
#
# no: don't fsync, just let the OS flush the data when it wants. Faster.
# always: fsync after every write to the append only log. Slow, Safest.
# everysec: fsync only one time every second. Compromise.
#
# The default is "everysec", as that's usually the right compromise between
# speed and data safety. It's up to you to understand if you can relax this to
# "no" that will let the operating system flush the output buffer when
# it wants, for better performances (but if you can live with the idea of
# some data loss consider the default persistence mode that's snapshotting),
# or on the contrary, use "always" that's very slow but a bit safer than
# everysec.
#
# More details please check the following article:
# http://antirez.com/post/redis-persistence-demystified.html
#
# If unsure, use "everysec".

# appendfsync always   AOF默認每秒寫一次,跟mysql的innodb redo刷新機制是同樣的
appendfsync everysec
# appendfsync no

 

八、各個版本的詳細配置可參考:oracle

 

九、重要的是:app

一、單進程架構,這意味着單個key的value不能過大,例如幾兆,這會嚴重影響TPS,具體拆分能夠參考:https://blog.csdn.net/beyond59241/article/details/78889867/
二、支持多database,不過最好使用多個instance的方式,有些客戶端可能不支持多instance,同時性能也比較難以排查
三、不支持namespace的概念,因此最好使用前提早規劃,好比namespace:key_name的方式,避免往後混亂
四、vm.swappiness=0 在os swap期間,進程會block直到完成,因此應該儘可能避免

十、客戶端緩衝大小配置,尤爲是是在行情接收場景中。https://blog.csdn.net/luyaoying001/article/details/80264347

十一、其它實踐能夠參考:https://www.cnblogs.com/ajianbeyourself/p/4472788.html

十二、避免快照所在盤磁盤空間滿,不然容易出現redis掛起。

相關文章
相關標籤/搜索