Performance: When encountering SQL queries that take a long time to execute and have results that don’t change frequently, it’s ideal to store the results in cache. This allows subsequent requests to read from cache, enabling rapid response times.
Concurrency: Under high concurrency, if all requests directly access the database, connection exceptions will occur. Redis serves as a buffer, allowing requests to access Redis first instead of directly hitting the database. (MySQL supports ~1,500 QPS, while Redis supports 20,000-50,000 QPS)
Redis Use Cases
Caching
Flash sales/spike traffic handling
Distributed locking
Redis Single-Threading Model
Key Concepts
Thread tasks: command processing, I/O handling, persistence, data synchronization
Version 6.0+: configurable multi-threading support
epoll + reactor pattern
High Performance Reasons
Memory operations: All data operations occur in memory
I/O Model on Linux: Uses epoll combined with reactor pattern
# A comma separated list of directories under which to store log files log.dirs=/home/kafka1,/home/kafka2,/home/kafka3 # Zookeeper connection string zookeeper.connect=zk1:2181,zk2:2181,zk3:2181/kafka1 # Timeout in ms for connecting to zookeeper zookeeper.connection.timeout.ms=18000 # The address the socket server listens on listeners=PLAINTEXT://:9092 # Hostname and port the broker will advertise advertised.listeners=PLAINTEXT://:9092 # Log retention settings log.retention.hours=168 log.retention.ms=15552000000 log.retention.bytes=1073741824 log.segment.bytes=1073741824 log.retention.check.interval.ms=300000
This is a safety mechanism which guarantees that only active members of the group are able to commit offsets. So to stay in the group, you must continue to call poll.
GC 参数
The recommended way to handle these cases is to move message processing to another thread, which allows the consumer to continue callingpollwhile the processor is still working. Some care must be taken to ensure that committed offsets do not get ahead of the actual position.
# The number of threads that the server uses for receiving requests from the network and sending responses to the network num.network.threads=3 # The number of threads that the server uses for processing requests, which may include disk I/O num.io.threads=8
# 修改配置 vi /etc/sysctl.conf # The percentage of how likely the VM subsystem is to use swap space rather than dropping pages from the page cache. vm.swappiness=1 # The percentage of the total amount of system memory, and setting this value to 5 is appropriate in many situations. vm.dirty_background_ratio=5