search
HomeDatabaseRedisWhat resources does redis mainly consume?

Redis in-process consumption mainly includes: own memory, object memory, buffer memory, and memory fragmentation.

What resources does redis mainly consume?

Memory. Because redis data is stored in memory. Compared with general relational databases, in-memory databases have faster reading speeds, but consume more memory resources.

Object memory(Recommended learning: Redis video tutorial)

Object memory is the largest piece of Redis memory and stores users All data. All data in Redis adopts key-value data type. Every time a key-value pair is created, at least two type objects are created: key object and value object. Memory consumption can be simply understood as sizeof(keys) sizeof(values). Key objects are all strings. When using Redis, it is easy to ignore the impact of keys on memory consumption. You should avoid using keys that are too long. The value object is more complex and mainly includes 5 basic data types: string, list, hash, set, and ordered set. Each value object type occupies different memory depending on the scale of use. When using it, you must reasonably estimate and monitor the value object occupancy to avoid memory overflow.

Buffer memory

Buffer memory mainly includes: client buffer, copy backlog buffer, and AOF buffer.

Client buffering refers to the input and output buffering of all TCP connections to the Redis server. The input and output buffer cannot be controlled. The maximum space is 1G. If it exceeds, the connection will be disconnected. Input buffering is controlled by the parameter client-output-buffer-limit:

1. Ordinary clients: For all connections except replicated and subscribed clients, the default configuration of Redis is: client-output-buffer- limit normal 0 0 0, Redis does not limit the output buffer of ordinary clients. Generally, the memory consumption of ordinary clients can be ignored, but when a large number of slow connection clients are connected, this part of the memory consumption cannot be ignored. Set maxclients to limit. Be careful not to just use commands that output a large amount of data and the data cannot be pushed to the client in time, such as the monitor command, which can easily cause the memory of the Redis server to suddenly surge.

Slave client: The master node will establish a separate connection for each slave node for command replication. The default configuration is: client-output-buffer-limit slave 256mb 64mb 60. When the network delay between the master and slave nodes is high or the master node mounts a large number of slave nodes, this part of the memory consumption will occupy a large part. It is recommended that the master node mount no more than 2 slave nodes, and the master and slave nodes should not be deployed in poor locations. In a certain network environment, such as across different computer rooms, prevent overflow caused by slow replication client connections.

Subscription client: When using the publish and subscribe function, the connection client uses a separate output buffer. The default configuration is: client-output-buffer-limit pubsub 32mb 8mb 60. When the message production of the subscription service is fast At the consumption speed, the output buffer will generate a backlog and cause the output buffer space to overflow.

Replication backlog buffer: Redis provides a reusable fixed-size buffer after version 2.8 to implement partial replication functions. It is controlled according to the repl-backlog-size parameter, and the default is 1MB. There is only one copy backlog buffer for the entire master node, and all slave nodes share this buffer, so a larger buffer space can be set, such as 100MB.

AOF buffer: This part of the space is used to save recent write commands during Redis rewriting.

3. Memory fragmentation

Redis’ default memory allocator uses jemalloc, and optional allocators include: glibc and tcmalloc. In order to better manage and reuse memory, the memory allocator generally uses a fixed range of memory blocks to allocate memory.

The following scenarios are prone to high memory fragmentation problems:

Frequent update operations, such as frequently performing append, setrange and other update operations on existing keys.

A large number of expired keys are deleted. After the key objects are expired and deleted, the released space cannot be fully utilized, resulting in an increase in the fragmentation rate.

For more Redis-related technical articles, please visit the Introduction to Using Redis Database Tutorial column to learn!

The above is the detailed content of What resources does redis mainly consume?. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
es和redis区别es和redis区别Jul 06, 2019 pm 01:45 PM

Redis是现在最热门的key-value数据库,Redis的最大特点是key-value存储所带来的简单和高性能;相较于MongoDB和Redis,晚一年发布的ES可能知名度要低一些,ES的特点是搜索,ES是围绕搜索设计的。

一起来聊聊Redis有什么优势和特点一起来聊聊Redis有什么优势和特点May 16, 2022 pm 06:04 PM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于redis的一些优势和特点,Redis 是一个开源的使用ANSI C语言编写、遵守 BSD 协议、支持网络、可基于内存、分布式存储数据库,下面一起来看一下,希望对大家有帮助。

实例详解Redis Cluster集群收缩主从节点实例详解Redis Cluster集群收缩主从节点Apr 21, 2022 pm 06:23 PM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis Cluster集群收缩主从节点的相关问题,包括了Cluster集群收缩概念、将6390主节点从集群中收缩、验证数据迁移过程是否导致数据异常等,希望对大家有帮助。

Redis实现排行榜及相同积分按时间排序功能的实现Redis实现排行榜及相同积分按时间排序功能的实现Aug 22, 2022 pm 05:51 PM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,希望对大家有帮助。

详细解析Redis中命令的原子性详细解析Redis中命令的原子性Jun 01, 2022 am 11:58 AM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于原子操作中命令原子性的相关问题,包括了处理并发的方案、编程模型、多IO线程以及单命令的相关内容,下面一起看一下,希望对大家有帮助。

一文搞懂redis的bitmap一文搞懂redis的bitmapApr 27, 2022 pm 07:48 PM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了bitmap问题,Redis 为我们提供了位图这一数据结构,位图数据结构其实并不是一个全新的玩意,我们可以简单的认为就是个数组,只是里面的内容只能为0或1而已,希望对大家有帮助。

实例详解Redis实现排行榜及相同积分按时间排序功能的实现实例详解Redis实现排行榜及相同积分按时间排序功能的实现Aug 26, 2022 pm 02:09 PM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了Redis实现排行榜及相同积分按时间排序,本文通过实例代码给大家介绍的非常详细,下面一起来看一下,希望对大家有帮助。

一起聊聊Redis实现秒杀的问题一起聊聊Redis实现秒杀的问题May 27, 2022 am 11:40 AM

本篇文章给大家带来了关于redis的相关知识,其中主要介绍了关于实现秒杀的相关内容,包括了秒杀逻辑、存在的链接超时、超卖和库存遗留的问题,下面一起来看一下,希望对大家有帮助。

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment