Redis基礎知識(學習筆記7--關鍵參數配置說明)

来源:https://www.cnblogs.com/xuliuzai/p/18263052
-Advertisement-
Play Games

Primer Premier是一款專業級PCR引物設計工具軟體,專為科研及分子生物學實驗定製PCR擴增、測序探針及雜交引物。該程式運用尖端演演算法評估引物的特異性、二聚體可能性和熔解溫度等核心屬性,確保產出的引物在性能上精準高效。其用戶友好界面不僅簡化了引物設計流程,並整合了序列比對與限制性內切酶位點 ...


1. 基礎說明

# Redis configuration file example.
#
# Note that in order to read the configuration file, Redis must be
# started with the file path as first argument:
#
# ./redis-server /path/to/redis.conf

# Note on units: when memory size is needed, it is possible to specify
# it in the usual form of 1k 5GB 4M and so forth:
#
# 1k => 1000 bytes
# 1kb => 1024 bytes
# 1m => 1000000 bytes
# 1mb => 1024*1024 bytes
# 1g => 1000000000 bytes
# 1gb => 1024*1024*1024 bytes
#
# units are case insensitive so 1GB 1Gb 1gB are all the same.

明確了 啟動方式,必須指定參數(文件)

Note that in order to read the configuration file, Redis must be started with the file path as first argument

例如  ./redis-server /path/to/redis.conf

另外,也說明瞭記憶體配置時,用到的大小單位,且單位是大小不敏感的。

2. INCLUDES

################################## INCLUDES ###################################

# Include one or more other config files here.  This is useful if you
# have a standard template that goes to all Redis servers but also need
# to customize a few per-server settings.  Include files can include
# other files, so use this wisely.

....

指定要在當前配置文件中包含的配置文件。這樣做的目的便於對配置信息的管理:可以將不同場景的配置進行單獨的定義,然後在當前核心配置文件中根據不同場景選擇包含進來不同的配置文件。

3.MODULES

################################## MODULES #####################################

# Load modules at startup. If the server is not able to load modules
# it will abort. It is possible to use multiple loadmodule directives.
#
# loadmodule /path/to/my_module.so
# loadmodule /path/to/other_module.so
# loadmodule /path/to/args_module.so [arg [arg ...]]

Redis 配置文件中可以通過載入不同的第三方模塊,來增強、擴展Redis的功能

4.網路NETWORK

################################## NETWORK #####################################

# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
# Each address can be prefixed by "-", which means that redis will not fail to
# start if the address is not available. Being not available only refers to
# addresses that does not correspond to any network interface. Addresses that
# are already in use will always fail, and unsupported protocols will always BE
# silently skipped.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1     # listens on two specific IPv4 addresses
# bind 127.0.0.1 ::1              # listens on loopback IPv4 and IPv6
# bind * -::*                     # like the default, all available interfaces
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 and IPv6 (if available) loopback interface addresses (this means Redis
# will only be able to accept client connections from the same host that it is
# running on).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# COMMENT OUT THE FOLLOWING LINE.
#
# You will also need to set a password unless you explicitly disable protected
# mode.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 127.0.0.1 -::1

# By default, outgoing connections (from replica to master, from Sentinel to
# instances, cluster bus, etc.) are not bound to a specific local address. In
# most cases, this means the operating system will handle that based on routing
# and the interface through which the connection goes out.
#
# Using bind-source-addr it is possible to configure a specific address to bind
# to, which may also affect how the connection gets routed.
#
# Example:
#
# bind-source-addr 10.0.0.1

# Protected mode is a layer of security protection, in order to avoid that
# Redis instances left open on the internet are accessed and exploited.
#
# When protected mode is on and the default user has no password, the server
# only accepts local connections from the IPv4 address (127.0.0.1), IPv6 address
# (::1) or Unix domain sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured.
protected-mode yes

# Redis uses default hardened security configuration directives to reduce the
# attack surface on innocent users. Therefore, several sensitive configuration
# directives are immutable, and some potentially-dangerous commands are blocked.
#
# Configuration directives that control files that Redis writes to (e.g., 'dir'
# and 'dbfilename') and that aren't usually modified during runtime
# are protected by making them immutable.
#
# Commands that can increase the attack surface of Redis and that aren't usually
# called by users are blocked by default.
#
# These can be exposed to either all connections or just local ones by setting
# each of the configs listed below to either of these values:
#
# no    - Block for any connection (remain immutable)
# yes   - Allow for any connection (no protection)
# local - Allow only for local connections. Ones originating from the
#         IPv4 address (127.0.0.1), IPv6 address (::1) or Unix domain sockets.
#
# enable-protected-configs no
# enable-debug-command no
# enable-module-command no

# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need a high backlog in order
# to avoid slow clients connection issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# Unix socket.
#
# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
# unixsocket /run/redis.sock
# unixsocketperm 700

# Close the connection after a client is idle for N seconds (0 to disable)
timeout 0

# TCP keepalive.
#
# If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
# of communication. This is useful for two reasons:
#
# 1) Detect dead peers.
# 2) Force network equipment in the middle to consider the connection to be
#    alive.
#
# On Linux, the specified value (in seconds) is the period used to send ACKs.
# Note that to close the connection the double of the time is needed.
# On other kernels the period depends on the kernel configuration.
#
# A reasonable value for this option is 300 seconds, which is the new
# Redis default starting with Redis 3.2.1.
tcp-keepalive 300

# Apply OS-specific mechanism to mark the listening socket with the specified
# ID, to support advanced routing and filtering capabilities.
#
# On Linux, the ID represents a connection mark.
# On FreeBSD, the ID represents a socket cookie ID.
# On OpenBSD, the ID represents a route table ID.
#
# The default value is 0, which implies no marking is required.
# socket-mark-id 0

說明:

(1) bind 127.0.0.1(IPv4 本地表示方法) -::1(IPv6 本地表示方法);預設的只能直接本地訪問

(2)protected-mode yes : 受保護模式, 開啟, 保證安全性;預設的只能直接本地訪問

(3)port: 指定埠號

(4)tcp-backlog:在linux系統中控制tcp三次握手已完成連接隊列的長度。在高併發系統中,通常需要設置一個較高的tcp-backlog來避免客戶端連接速度慢的問題(三次握手的速度)。已完成連接隊列的長度也與操作系統中somaxconn參數有關,取二者最小min(tcp-backlog,somaxconn)。linux查看已完成連接隊列的長度:$ /proc/sys/net/core/somaxconn

【tcp-backlog是一個TCP連接的隊列,主要用於解決高併發場景下客戶端慢連接問題。這裡設置的值就是這個隊列的長度。該隊列與TCP連接的三次握手有關,不同的linux內核,backlog隊列中存放的元素(客戶端連接)類型是不同的。

***Linux內核2.2版本之前,該隊列中存放的是已經完成了第一次握手的所有客戶端連接,其中就包含已完成三次握手的客戶端連接。此時的backlog隊列中的連接具有兩種狀態:未完成三次握手的連接狀態SYN_RECEIVED,已完成三次握手連接狀態為ESTABLISHED,只有ESTABLISHED狀態的連接才會被Redis處理。

***Linux內核2.2版本之後,TCP系統維護了兩個隊列:SYN_RECEIVED隊列和ESTABLISHED隊列。SYN_RECEIVED隊列中存放的是未完成三次握手的連接;ESTABLISHED隊列中存放的是已完成三次握手的連接,此時的的backlog就是ESTABLISHED隊列。 】

補充下知識點 --查看Linux內核版本

uname -a
或
cat /proc/version

補充下知識點 --修改somaxconn的方法步驟

step 1
vim /etc/sysctl.conf   ##打開配置文件
step 2
net.core.somaxconn=2048 ##文件最後 添加這樣一句話,此處2048代表你要修改後的值,請註意替換。
step 3
文件保存退出。
step 4
sysctl -p   ##重啟生效

 

(5)timeout:不再使用的連接 超時時間(關閉時間),單位秒;超過timeout,服務端會斷開連接。為0則服務端不會主動斷開連接(依賴於TCP 本身的預設屬性,為2H後斷開),不能小於0

(6)tcp-keepalive:表示針對空閑連接,為了保持可用,server 端每隔tcp-keepalive這麼長的時間,就去探測一下。

5.TLS/SSL模塊

################################# TLS/SSL #####################################

# By default, TLS/SSL is disabled. To enable it, the "tls-port" configuration
# directive can be used to define TLS-listening ports. To enable TLS on the
# default port, use:

6.GENERAL模塊

################################# GENERAL #####################################
。。。。。。。。。

6.1 daemonize 

預設值為no

預設情況下,Redis不作為守護進程運行(老版本預設)。如果需要可以修改daemonize為‘yes’。

註意,Redis在守護進程時會在var/run/redis.pid中寫入一個pid文件。當Redis被upstart或systemd監管時,這個參數沒有影響。

6.2 pidfile

該配置用於指定redis允許時pid寫入的文件,無論是否採用守護進程的方式啟動,pid都會寫入到該配置的文件中。

說明:如果沒有在conf文件中顯式配置pid文件,不同的啟動方式,pid文件產生的效果是不同的:(1)採用守護進程方式啟動(後臺方式啟動即daemonize 為yes):pid文件為 /var/run/redis.pid。(2)採用前臺方式啟動(daemonize 為no):不產生pid文件。

6.3  loglevel notice 和 logfile ""

日誌級別 和 日誌文件

關於logfile的說明:指定日誌文件。如果設置為空字元串,則強制將日誌記錄到標準輸出設備(顯示器)。如果使用的是守護進程方式啟動,設置為空串,則意味著將日誌發送到設備/dev/null(空設備--即不顯示)。--所以這個建議進行設置。

6.4 databases 16

設置資料庫的數量。預設資料庫是0號資料庫。可以使用select<dbid>,在每個連接上進行選擇。其中dbid介於0 和’databases‘-1 之間的數字。

7.安全策略

################################## SECURITY ###################################

# Warning: since Redis is pretty fast, an outside user can try up to
# 1 million passwords per second against a modern box. This means that you
# should use very strong passwords, otherwise they will be very easy to break.
# Note that because the password is really a shared secret between the client
# and the server, and should not be memorized by any human, the password
# can be easily a long string from /dev/urandom or whatever, so by using a
# long and unguessable password no brute force attack will be possible.

# Redis ACL users are defined in the following format:
#
#   user <username> ... acl rules ...
#
# For example:
#
#   user worker +@list +@connection ~jobs:* on >ffa9203c493aa99
#
# The special username "default" is used for new connections. If this user
# has the "nopass" rule, then new connections will be immediately authenticated
# as the "default" user without the need of any password provided via the
# AUTH command. Otherwise if the "default" user is not flagged with "nopass"
# the connections will start in not authenticated state, and will require
# AUTH (or the HELLO command AUTH option) in order to be authenticated and
# start to work.
#
# The ACL rules that describe what a user can do are the following:
#
#  on           Enable the user: it is possible to authenticate as this user.
#  off          Disable the user: it's no longer possible to authenticate
#               with this user, however the already authenticated connections
#               will still work.
#  skip-sanitize-payload    RESTORE dump-payload sanitization is skipped.
#  sanitize-payload         RESTORE dump-payload is sanitized (default).
#  +<command>   Allow the execution of that command.
#               May be used with `|` for allowing subcommands (e.g "+config|get")
#  -<command>   Disallow the execution of that command.
#               May be used with `|` for blocking subcommands (e.g "-config|set")
#  +@<category> Allow the execution of all the commands in such category
#               with valid categories are like @admin, @set, @sortedset, ...
#               and so forth, see the full list in the server.c file where
#               the Redis command table is described and defined.
#               The special category @all means all the commands, but currently
#               present in the server, and that will be loaded in the future
#               via modules.
#  +<command>|first-arg  Allow a specific first argument of an otherwise
#                        disabled command. It is only supported on commands with
#                        no sub-commands, and is not allowed as negative form
#                        like -SELECT|1, only additive starting with "+". This
#                        feature is deprecated and may be removed in the future.
#  allcommands  Alias for +@all. Note that it implies the ability to execute
#               all the future commands loaded via the modules system.
#  nocommands   Alias for -@all.
#  ~<pattern>   Add a pattern of keys that can be mentioned as part of
#               commands. For instance ~* allows all the keys. The pattern
#               is a glob-style pattern like the one of KEYS.
#               It is possible to specify multiple patterns.
# %R~<pattern>  Add key read pattern that specifies which keys can be read 
#               from.
# %W~<pattern>  Add key write pattern that specifies which keys can be
#               written to. 
#  allkeys      Alias for ~*
#  resetkeys    Flush the list of allowed keys patterns.
#  &<pattern>   Add a glob-style pattern of Pub/Sub channels that can be
#               accessed by the user. It is possible to specify multiple channel
#               patterns.
#  allchannels  Alias for &*
#  resetchannels            Flush the list of allowed channel patterns.
#  ><password>  Add this password to the list of valid password for the user.
#               For example >mypass will add "mypass" to the list.
#               This directive clears the "nopass" flag (see later).
#  <<password>  Remove this password from the list of valid passwords.
#  nopass       All the set passwords of the user are removed, and the user
#               is flagged as requiring no password: it means that every
#               password will work against this user. If this directive is
#               used for the default user, every new connection will be
#               immediately authenticated with the default user without
#               any explicit AUTH command required. Note that the "resetpass"
#               directive will clear this condition.
#  resetpass    Flush the list of allowed passwords. Moreover removes the
#               "nopass" status. After "resetpass" the user has no associated
#               passwords and there is no way to authenticate without adding
#               some password (or setting it as "nopass" later).
#  reset        Performs the following actions: resetpass, resetkeys, resetchannels,
#               allchannels (if acl-pubsub-default is set), off, clearselectors, -@all.
#               The user returns to the same state it has immediately after its creation.
# (<options>)   Create a new selector with the options specified within the
#               parentheses and attach it to the user. Each option should be 
#               space separated. The first character must be ( and the last 
#               character must be ).
# clearselectors            Remove all of the currently attached selectors. 
#                           Note this does not change the "root" user permissions,
#                           which are the permissions directly applied onto the
#                           user (outside the parentheses).
#
# ACL rules can be specified in any order: for instance you can start with
# passwords, then flags, or key patterns. However note that the additive
# and subtractive rules will CHANGE MEANING depending on the ordering.
# For instance see the following example:
#
#   user alice on +@all -DEBUG ~* >somepassword
#
# This will allow "alice" to use all the commands with the exception of the
# DEBUG command, since +@all added all the commands to the set of the commands
# alice can use, and later DEBUG was removed. However if we invert the order
# of two ACL rules the result will be different:
#
#   user alice on -DEBUG +@all ~* >somepassword
#
# Now DEBUG was removed when alice had yet no commands in the set of allowed
# commands, later all the commands are added, so the user will be able to
# execute everything.
#
# Basically ACL rules are processed left-to-right.
#
# The following is a list of command categories and their meanings:
# * keyspace - Writing or reading from keys, databases, or their metadata 
#     in a type agnostic way. Includes DEL, RESTORE, DUMP, RENAME, EXISTS, DBSIZE,
#     KEYS, EXPIRE, TTL, FLUSHALL, etc. Commands that may modify the keyspace,
#     key or metadata will also have `write` category. Commands that only read
#     the keyspace, key or metadata will have the `read` category.
# * read - Reading from keys (values or metadata). Note that commands that don't
#     interact with keys, will not have either `read` or `write`.
# * write - Writing to keys (values or metadata)
# * admin - Administrative commands. Normal applications will never need to use
#     these. Includes REPLICAOF, CONFIG, DEBUG, SAVE, MONITOR, ACL, SHUTDOWN, etc.
# * dangerous - Potentially dangerous (each should be considered with care for
#     various reasons). This includes FLUSHALL, MIGRATE, RESTORE, SORT, KEYS,
#     CLIENT, DEBUG, INFO, CONFIG, SAVE, REPLICAOF, etc.
# * connection - Commands affecting the connection or other connections.
#     This includes AUTH, SELECT, COMMAND, CLIENT, ECHO, PING, etc.
# * blocking - Potentially blocking the connection until released by another
#     command.
# * fast - Fast O(1) commands. May loop on the number of arguments, but not the
#     number of elements in the key.
# * slow - All commands that are not Fast.
# * pubsub - PUBLISH / SUBSCRIBE related
# * transaction - WATCH / MULTI / EXEC related commands.
# * scripting - Scripting related.
# * set - Data type: sets related.
# * sortedset - Data type: zsets related.
# * list - Data type: lists related.
# * hash - Data type: hashes related.
# * string - Data type: strings related.
# * bitmap - Data type: bitmaps related.
# * hyperloglog - Data type: hyperloglog related.
# * geo - Data type: geo related.
# * stream - Data type: streams related.
#
# For more information about ACL configuration please refer to
# the Redis web site at https://redis.io/docs/latest/operate/oss_and_stack/management/security/acl/.

# ACL LOG
#
# The ACL Log tracks failed commands and authentication events associated
# with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
# by ACLs. The ACL Log is stored in memory. You can reclaim memory with
# ACL LOG RESET. Define the maximum entry length of the ACL Log below.
acllog-max-len 128

# Using an external ACL file
#
# Instead of configuring users here in this file, it is possible to use
# a stand-alone file just listing users. The two methods cannot be mixed:
# if you configure users here and at the same time you activate the external
# ACL file, the server will refuse to start.
#
# The format of the external ACL user file is exactly the same as the
# format that is used inside redis.conf to describe users.
#
# aclfile /etc/redis/users.acl

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
# The requirepass is not compatible with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared

# New users are initialized with restrictive permissions by default, via the
# equivalent of this ACL rule 'off resetkeys -@all'. Starting with Redis 6.2, it
# is possible to manage access to Pub/Sub channels with ACL rules as well. The
# default Pub/Sub channels permission if new users is controlled by the
# acl-pubsub-default configuration directive, which accepts one of these values:
#
# allchannels: grants access to all Pub/Sub channels
# resetchannels: revokes access to all Pub/Sub channels
#
# From Redis 7.0, acl-pubsub-default defaults to 'resetchannels' permission.
#
# acl-pubsub-default resetchannels

# Command renaming (DEPRECATED).
#
# ------------------------------------------------------------------------
# WARNING: avoid using this option if possible. Instead use ACLs to remove
# commands from the default user, and put them only in some admin user you
# create for administrative purposes.
# ------------------------------------------------------------------------
#
# It is possible to change the name of dangerous commands in a shared
# environment. For instance the CONFIG command may be renamed into something
# hard to guess so that it will still be available for internal-use tools
# but not available for general clients.
#
# Example:
#
# rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
#
# It is also possible to completely kill a command by renaming it into
# an empty string:
#
# rename-command CONFIG ""
#
# Please note that changing the name of commands that are logged into the
# AOF file or transmitted to replicas may cause problems.

(1)requirepass 安全設置

可以通過 # requirepass foobared,進行手動設置。而命令行設置 : config set requirepass "????" 。若已設置密碼則需要登錄 命令 : auth XXXX 。登錄成功 獲取用戶密碼 : config get requirepass。

 (2)rename-command 安全設置

 改寫命令;例如,我們禁用 flushall、flushdb的命令

那麼可以在 # rename-command CONFIG "" 加上下麵腳本:

# rename-command CONFIG ""
rename-command flushall ""  ##禁用flushall;刪除所有DB
rename-connand flushdb "" ##禁用flushdb;只刪除當前DB

 8. CLIENTS 部分

################################### CLIENTS ####################################

# Set the max number of connected clients at the same time. By default
# this limit is set to 10000 clients, however if the Redis server is not
# able to configure the process file limit to allow for the specified limit
# the max number of allowed clients is set to the current file limit
# minus 32 (as Redis reserves a few file descriptors for internal uses).
#
# Once the limit is reached Redis will close all the new connections sending
# an error 'max number of clients reached'.
#
# IMPORTANT: When Redis Cluster is used, the max number of connections is also
# shared with the cluster bus: every node in the cluster will use two
# connections, one incoming and another outgoing. It is important to size the
# limit accordingly in case of very large clusters.
#
# maxclients 10000

該模塊用於設置與客戶端相關的屬性,其中僅包含一個屬性maxclients。

maxclients用於設置redis可併發處理的客戶端連接數量,預設為10000。如果到達了該最大連接數,則會拒絕新的連接,並返回一個異常信息--max number of clients reached 

註意: 還受限於 the process file limit to allow for the specified limit【可打開的文件描述符最大閾值】

其設置查看的命令

ulimit -m

9.MEMORY MANAGEMENT 

該配置可以控制最大可用記憶體即相關內容移除問題。

############################## MEMORY MANAGEMENT ################################

# Set a memory usage limit to the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys
# according to the eviction policy selected (see maxmemory-policy).
#
。。。。。。。。。

9.1  maxmemory <bytes>

設置記憶體最大使用值,單位為位元組數。當記憶體達到記憶體限制時,redis將根據選擇的逐出策略 maxmemory-policy,嘗試刪除符合條件的key。

如果策略設置的是不移除,則會給寫操作命令返回Error。對於只讀的命令,沒影響。

9.2 maxmemory-policy

逐出策略。

# MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
# is reached. You can select one from the following behaviors:
#
# volatile-lru -> Evict using approximated LRU, only keys with an expire set.
# allkeys-lru -> Evict any key using approximated LRU.
# volatile-lfu -> Evict using approximated LFU, only keys with an expire set.
# allkeys-lfu -> Evict any key using approximated LFU.
# volatile-random -> Remove a random key having an expire set.
# allkeys-random -> Remove a random key, any key.
# volatile-ttl -> Remove the key with the nearest expire time (minor TTL)
# noeviction -> Don't evict anything, just return an error on write operations.
#

9.3 maxmemory-samples 5

# LRU, LFU and minimal TTL algorithms are not precise algorithms but approximated
# algorithms (in order to save memory), so you can tune it for speed or
# accuracy. By default Redis will check five keys and pick the one that was
# used least recently, you can change the sample size using the following
# configuration directive.
#
# The default of 5 produces good enough results. 10 Approximates very closely
# true LRU but costs more CPU. 3 is faster but not very accurate. The maximum
# value that can be set is 64.
#

該屬性用於指定挑選要刪除的key的樣本數量。樣本的選擇採用的是LRU演算法,其不能修改。單從樣本中再選擇移除的key,採用的是maxmemory-policy參數指定的演算法。

9.4 maxmemory-eviction-tenacity 10

設置移除容忍度。數值越小表示容忍度越低,需要移除的數據移除延遲越小;數值越大,表示容忍度越高,需要移除的數據移除延遲越大。

10.THREADED I/O

該配置模塊用於配置Redis對多線程IO模型的支持。

################################ THREADED I/O #################################

# Redis is mostly single threaded, however there are certain threaded
# operations such as UNLINK, slow I/O accesses and other things that are
# performed on side threads.
#
# Now it is also possible to handle Redis clients socket reads and writes
# in different I/O threads. Since especially writing is so slow, normally
# Redis users use pipelining in order to speed up the Redis performances per
# core, and spawn multiple instances in order to scale more. Using I/O
# threads it is possible to easily speedup two times Redis without resorting
# to pipelining nor sharding of the instance.
#
# By default threading is disabled, we suggest enabling it only in machines
# that have at least 4 or more cores, leaving at least one spare core.
# Using more than 8 threads is unlikely to help much. We also recommend using
# threaded I/O only if you actually have performance problems, with Redis
# instances being able to use a quite big percentage of CPU time, otherwise
# there is no point in using this feature.
#
# So for instance if you have a four cores boxes, try to use 2 or 3 I/O
# threads, if you have a 8 cores, try to use 6 threads. In order to
# enable I/O threads use the following configuration directive:
#
# io-threads 4
#
# Setting io-threads to 1 will just use the main thread as usual.
# When I/O threads are enabled, we only use threads for writes, that is
# to thread the write(2) syscall and transfer the client buffers to the
# socket. However it is also possible to enable threading of reads and
# protocol parsing using the following configuration directive, by setting
# it to yes:
#
# io-threads-do-reads no
#
# Usually threading reads doesn't help much.
#
# NOTE 1: This configuration directive cannot be changed at runtime via
# CONFIG SET. Also, this feature currently does not work when SSL is
# enabled.
#
# NOTE 2: If you want to test the Redis speedup using redis-benchmark, make
# sure you also run the benchmark itself in threaded mode, using the
# --threads option to match the number of Redis threads, otherwise you'll not
# be able to notice the improvements.

(1)io-threads

該屬性用於指定要啟用多線程IO模型時,需使用的線程數量。

(2)io-threads-do-reads

將io線程設置為1將照常使用主線程。當啟用IO線程時,只使用線程進行寫入,也就是說,通過線程執行write(2)系統調用,並將客戶端緩衝區傳輸到套接字。

但是,也可以使用以下配置指令啟用讀取線程和協議解析,方法是將其設置為yes.

補充知識--查看CPU的命令

lscpu

 

補充知識--redis 關閉方式

redis-cli shutdown

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 本文介紹在Linux Ubuntu操作系統的電腦中,安裝Anaconda環境與Python語言的方法。 在之前的文章Anaconda與Python環境在Windows中的部署中,我們介紹了在Win10電腦中,安裝Anaconda環境與Python語言的方法;而在本文中,我們就詳細介紹一下在Linux ...
  • 0、思考與回答 0.1、思考一 如何處理進入阻塞狀態的任務? 為了讓 RTOS 支持多優先順序,我們創建了多個就緒鏈表(數組形式),用每一個就緒鏈表表示一個優先順序,對於阻塞狀態的任務顯然要從就緒鏈表中移除,但是阻塞狀態的任務並不是永久阻塞了,等待一段時間後應該從阻塞狀態恢復,所以我們需要創建一個阻塞鏈 ...
  • liwen01 2024.06.16 前言 先提幾個問題:什麼是文件系統崩潰一致性?為什麼會出現文件系統崩潰一致性問題?有哪些方法可以解這個問題?它們各自又有哪些局限性? window系統電腦異常後會藍屏、手機死機卡頓後我們會手動給它重啟,大部分設備的系統在遇到不可修複的嚴重異常後都會嘗試通過重啟來 ...
  • 本文介紹瞭如何根據所使用的不同開發板配置不同的交叉編譯環境. 由於在移植LVGL到不同開發板上時遇到了一些問題, 故在問題解決後整理和總結和該文章. ...
  • 隨著技術的發展,用戶對軟體的界面美觀度和交互體驗的要求越來越高。在這樣的背景下,可視化開發UI(User Interface)成為了提升用戶體驗和開發效率的重要工具。 通過圖形界面來設計和構建用戶界面的方法,可視化開發UI可以說改變了軟便開發的生態,與傳統的代碼編寫相比,它允許開發者使用拖放等直觀的 ...
  • 本文分享自天翼雲開發者社區《TiDB體系架構》,作者:x****n 如圖所示,TiDB體系中三大組成部分:PD、TiDB Server、TiKV 1.PD:負責產生全局的TSO時間、控制Region在TIkv中的分佈、產生全局事務ID、還有其他ID。 2.TiDB:沒有數據落地,接收客戶端sql語句 ...
  • 本文分享自華為雲社區《MySQL全文索引源碼剖析之Insert語句執行過程》,作者:GaussDB 資料庫。 本文主要介紹MySQL 8.0數據字典的基本概念和數據字典的初始化與啟動載入的主要流程。 MySQL 8.0數據字典簡介 數據字典(Data Dictionary, DD)用來存儲資料庫內部 ...
  • 哨兵模式 官方文檔:https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel 關聯博客:Redis主從複製(下文能用到) 極簡概括:自動監控Redis主節點是否故障的一種方案,若主節點故障,則Redis會根據投票數自 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...