最近在写项目时,采用的是单Activity+多Fragment的架构,用的Fragmentation的库。 我的主页面是一个BootomFragment的抽象类(当然它还有一个管理类),其又继承自最大的LatteDelegate,LatteDelegate又继承自Fragment并实现Fragmentation 这时候当再次点返回键,就成为了Fragmentation库默认的返回方法,也就是根据栈内Fragment,逐一退栈。
mem_fragmentation_ratio = used_memory_rss / used_memory 但Redis申请了这么多内存是在干啥呢??? Tracking fragmentation ratio is important for understanding your Redis instance’s performance. A fragmentation ratio greater than 1 indicates fragmentation is occurring. A fragmentation ratio below 1 tells you that Redis needs more memory than is available on your system will allow the operating system to recover memory previously unusable due to fragmentation.
Index Fragmentation(索引碎片) SQL Server的index fragmentation有两种:external fragmentation和internal fragmentation External fragmentation: Index page的逻辑顺序不连续时,叫做external fragmentation。 另外,external fragmentation对缓存效率产生影响。 External fragmentation使用两个方面的指标来描述,page的连续程度和extent的连续程度。 Internal fragmentation: Index page中如果存储空间未达到最大存储容量,叫做internal fragmentation。 Logical Scan Fragmentation:另外一个非常有意义的值,指示page的非连续程度,反应external fragmentation的重要统计信息之一。
used_memory_lua_human:37.00K maxmemory:10737418240 maxmemory_human:10.00G maxmemory_policy:volatile-lfu mem_fragmentation_ratio :1.21 mem_allocator:jemalloc-4.0.3 active_defrag_running:0 lazyfree_pending_objects:0 可以看到 mem_fragmentation_ratio redis4 碎片整理相关的配置说明: # Enabled active defragmentation # 碎片整理总开关 # activedefrag yes # Minimum amount of fragmentation to start active defrag # 内存碎片达到多少的时候开启整理 active-defrag-ignore-bytes 100mb # Minimum percentage of fragmentation to start active defrag # 碎片率达到百分之多少开启整理 active-defrag-threshold-lower 30 # Maximum percentage of fragmentation
而之前就做着性能优化的活,也顺手接下了优化Redis的活 内存碎片率mem_fragmentation_ratio 查阅相关资料得知,速度过慢很有可能是因为内存不足使用了swap导致。 而mem_fragmentation_ratio是一个很明显的是否使用了swap的指标。 mem_fragmentation_ratio的计算公式为 MemFragmentationRatio = \frac {UsedMemoryRss} {UsedMemory} 而我Redis执行info Fragmentation ratio < 1 but not swapping. #946 antirez commented on 15 Feb 2013 Hello, in your case 综上所述,mem_fragmentation_ratio只是一个可能反应性能指标的东西,而并不完全能反应性能指标。 那为啥我的Redis这么慢 ?
1024.00M used_memory_rss:1997159792 ## OS分配给redis的物理内存空间,其中包含内存碎片 used_memory_rss_human:1.86G … mem_fragmentation_ratio :1.86 指标mem_fragmentation_ratio:1.86 表示当前的内存碎片率, 计算公式为mem_fragmentation_ratio = used_memory_rss/ used_memory 所以,mem_fragmentation_ratio=1应该是最理想的情况 内存碎片严重程度 产生内存碎片不可避免,那么内存碎片率达到多少需要进行清理呢,这里有个经验阈值 1 < mem_fragmentation_ratio < 1.5 ,可以认为是合理的,无需处理 mem_fragmentation_ratio > 1.5, 表示内存碎片率超过50%,需要进行处理 当然还有可能存在一种情况,即内存碎片率 小于1: 这时候就说明
> 5 ORDER BY avg_fragmentation_in_percent DESC --打开游标 OPEN indexFragment_cursor FETCH NEXT objectid, www.2cto.com index_id AS indexid, partition_number AS partitionnum, avg_fragmentation_in_percent AS fra FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED') WHERE avg_fragmentation_in_percent object_id AS objectid, index_id AS indexid, partition_number AS partitionnum, avg_fragmentation_in_percent #work_to_do FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL , NULL, 'LIMITED') WHERE avg_fragmentation_in_percent
mem_fragmentation_ratio:内存碎片率,used_memory_rss / used_memory。 " 52) "0.0087051792070269585" 53) "fragmentation.bytes" 54) (integer) -897408432 2.2.5、memory usage 返回一个 waste to start active defrag # active-defrag-ignore-bytes 100mb # Minimum percentage of fragmentation to start active defrag # active-defrag-threshold-lower 10 # Maximum percentage of fragmentation at (内存碎片率),当mem_fragmentation_ratio > 1.5 时,建议开始清理内存碎片。
used_memory_peak:2001274696 //占用内存的峰值(字节) used_memory_peak_human:1.86G //占用内存的峰值(带单位的,可读性好) mem_fragmentation_ratio mem_fragmentation_ratio = used_memory_rss / used_memory mem_fragmentation_ratio,越低越高,趋向于1,大于1的部分redis
Redis 内存碎片率的计算公式:mem_fragmentation_ratio (内存碎片率)= used_memory_rss (操作系统实际分配给 Redis 的物理内存空间大小)/ used_memory (Redis 内存分配器为了存储数据实际申请使用的内存空间大小) 也就是说,mem_fragmentation_ratio (内存碎片率)的值越大代表内存碎片率越严重。 通常情况下,我们认为 mem_fragmentation_ratio > 1.5 的话才需要清理内存碎片。 mem_fragmentation_ratio > 1.5 意味着你使用 Redis 存储实际大小 2G 的数据需要使用大于 3G 的内存。 如果想要快速查看内存碎片率的话,你还可以通过下面这个命令: > redis-cli -p 6379 info | grep mem_fragmentation_ratio 另外,内存碎片率可能存在小于
working in low memory mode 解决方案 修改zabbix_server.conf配置的ValueCacheSize=2048M 四、Redis相关 1、告警:Redis: Memory fragmentation ratio is too high (over 1.5 in 15m) 内存碎片率:mem_fragmentation_ratio = used_memory_rss / used_memory mem_fragmentation_ratio < 1 表示Redis内存分配超出了物理内存,操作系统正在进行内存交换,内存交换会引起非常明显的响应延迟; mem_fragmentation_ratio > 1 是合理的; mem_fragmentation_ratio > 1.5 说明Redis消耗了实际需要物理内存的150%以上,其中50%是内存碎片率,可 内存碎片率略高于1是属于正常,但超出 used_memory_rss会越来越大,导致mem_fragmentation_ratio越来越高 解决方案 因编译的时候内存分配器非jemalloc,需要重新使用jemalloc编译。
Redis内存碎片率(mem_fragmentation_ratio) 计算公式: mem_fragmentation_ratio = used_memory_rss / used_memory ratio #Enabled active defragmentation #碎片整理总开关 #activedefrag yes #Minimum amount of fragmentation waste to start active defrag #当碎片达到 100mb 时, 开启内存碎片整理 active-defrag-ignore-bytes 100mb #Minimum percentage of fragmentation start active defrag #当碎片超过 10% 时, 开启内存碎片整理 active-defrag-threshold-lower 10 #Maximum percentage of fragmentation 25) "dataset.percentage" 26) "19.235012054443359" 27) "peak.percentage" 28) "93.1395263671875" 29) "fragmentation
内存碎片(Memory Fragmentation)现象:Redis的used_memory_rss(操作系统实际分配的内存)远大于used_memory(Redis实际使用的内存),导致内存碎片率(mem_fragmentation_ratio 检查内存碎片率 redis-cli INFO MEMORY | grep "mem_fragmentation_ratio"判断标准:mem_fragmentation_ratio < 1:内存不足,
:1073741736 used_memory_human:1024.00M used_memory_rss:1997159792 used_memory_rss_human:1.86G … mem_fragmentation_ratio :1.86 mem_fragmentation_ratio: Redis 当前的内存碎片率 used_memory_rss: 操作系统实际分配给 Redis 的物理内存空间,里面就包含了碎片 used_memory : Redis 为了保存数据实际申请使用的空间 mem_fragmentation_ratio = used_memory_rss/ used_memory 经验阈值: mem_fragmentation_ratio mem_fragmentation_ratio 大于 1.5 。这表明内存碎片率已经超过了 50%。一般情况下,这个时候,我们就需要采取一些措施来降低内存碎片率了。 如何清理内存碎片?
行碎片( Row fragmentation) 这种碎片指的是数据行被存储为多个地方的多个片段中。即使查询只从索引中访问行记录,行碎片也会导致性能下降。 行间碎片( Intra- row fragmentation) 行间碎片是指逻辑上顺序的页,或者行在磁盘上不是顺序存储的。 剩空间碎片( Free space fragmentation) 剩余空间碎片是指数据页中有大量的空余空间。这会导致服务器读取大量不需要的数据,从而造成浪费。
Fragmentation External Fragmentation 释放了五个单位的空间,又申请了四个单位的空间,则原空间只能分配一个单位,而不能被更大的分配需求利用。 Internal Fragmentation 记录的额外空间或者内存对齐,导致零碎的空间产生。
= 1.0 - (max_contiguous_free / free_memory) return fragmentation_rate def detect_fragmentation(self) -> Dict: """检测显存碎片情况""" fragmentation_rate = self.calculate_fragmentation_rate return { "fragmentation_rate": fragmentation_rate, "level": level, ": self.memory_manager.fragmentation_detector.calculate_fragmentation_rate(), "fragmentation_rate_after ": self.memory_manager.fragmentation_detector.calculate_fragmentation_rate(), "stats": self.stats
zone扫描已经完成,但是没有规整出合适的页 COMPACT_PARTIAL_SKIPPED: 扫描了部分的zone,但是没有找到合适的页 COMPACT_SUCCESS:规整成功,并且合并出空闲的页 fragmentation alloc_flags, classzone_idx, zone_page_state(zone, NR_FREE_PAGES)); /* * fragmentation index determines if allocation failures are due to * low memory or external fragmentation towards 0 implies failure is due to lack of memory * index towards 1000 implies failure is due to fragmentation * * Only compact if a failure would be due to fragmentation.
used_memory_peak:33979824 used_memory_peak_human:32.41M ... maxmemory:0 maxmemory_human:0B ... mem_fragmentation_ratio used_memory_rss:从os视角看分配多少内存给Redis used_memory_rss 除以 used_memory 就是内存碎片率(mem_fragmentation_ratio): used_memory_rss (39575552) / used_memory(26276368) = mem_fragmentation_ratio(1.51) 碎片化率较高说明 used_memory_rss 相对大,used_memory 随应用程序不断删除、修改Redis数据,内存碎片化率也会上升,mem_fragmentation_ratio>1.5,就说明碎片率太高,需重启 Redis或命令Redis清理碎片: CONFIG SET activedefrag yes 搞得很紧张啊,这大可不必,就像这例,RSS才占37M,Redis实际使用25M,碎片12M,很小啊,虽 mem_fragmentation_ratio已1.51 ,但无需处理
allocations 2004-05-10 Active memory defragmentation 2005-02-01 Yet another approach to memory fragmentation 2005-11-02 Fragmentation avoidance 2005-11-08 More on fragmentation avoidance 2006-11-28 Avoiding - and fixing - memory fragmentation 2010-01-06 Memory compaction 2014-03-26 Memory compaction issues 2016-05-10 make direct compaction more deterministic 2017-03-21 Proactive compaction 2018-10-31 Fragmentation