memoryKit

package
v2.8.154 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 21, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetMachineMemoryStats func() (*mem.VirtualMemoryStat, error) = mem.VirtualMemory

GetMachineMemoryStats 获取(当前瞬间的)服务器内存状态.

PS: (1) Total = Available + Used(???存疑,yozo有台Linux不符合) (2) UsedPercent: 内存使用率 e.g.50.903940200805664 (3) Free和Available的区别:

简单来说,Free内存是未被使用且处于空闲状态的内存,而Available内存则包括了已经被使用但可以释放的内存,例如缓存和缓冲区等.
Available内存是一个 "估计值" ,表示在不使用交换空间的情况下可以使用多少内存。

mem.VirtualMemoryStat 结构体的字段: (1) Total 总内存 (2) Available 可用内存(未被使用且处于空闲状态的内存 + 已经被使用但可以释放的内存,例如缓存和缓冲区等) (3) Used 已使用内存 (4) UsedPercent 内存使用百分比 (5) Free 空闲状态的内存

Functions

func GetAvailableMachineMemory added in v2.2.50

func GetAvailableMachineMemory() (uint64, error)

func GetProgramMemoryStats added in v2.1.37

func GetProgramMemoryStats() *runtime.MemStats

GetProgramMemoryStats 获取有关Go程序的实时内存统计信息.

runtime.MemStats结构体的的字段: (1) Alloc(单位: 字节)

Alloc is bytes of allocated heap objects.
分配的堆对象的字节数。

(2) TotalAlloc(单位: 字节)

TotalAlloc is cumulative bytes allocated for heap objects.
堆对象分配的累积字节数。与 Alloc 不同,当对象被释放时它不会减少。

(3) Sys(单位: 字节)

Sys is the total bytes of memory obtained from the OS.
从操作系统获得的内存总字节数。这测量了 Go 运行时为堆、栈和其他内部数据结构保留的虚拟地址空间。

(4) NumGC

NumGC is the number of completed GC cycles.
它表示自程序启动以来垃圾回收器运行的次数。每次垃圾回收器运行时,NumGC 的值都会增加。这个字段可以用来监控程序的垃圾回收情况。
!!!: 如果你发现 NumGC 的值增长得非常快,那么可能意味着你的程序存在内存分配问题。

(5) EnableGC

EnableGC indicates that GC is enabled. It is always true, even if GOGC=off.
表示是否允许垃圾回收。它是一个 bool 类型,如果为 true,则允许垃圾回收;如果为 false,则禁止垃圾回收。

(6) DebugGC

DebugGC is currently unused.
表示是否启用调试垃圾回收。它是一个 bool 类型,如果为 true,则启用调试垃圾回收;如果为 false,则禁用调试垃圾回收。

func SetSoftMemoryLimit

func SetSoftMemoryLimit(limit uint64) (int64, error)

SetSoftMemoryLimit 软内存限制(soft memory limit)

PS: (1) This limit will be respected even if GOGC=off (or, if SetGCPercent(-1) is executed). (2) 默认memory limit是math.MaxInt64(即第一次调用debug.SetMemoryLimit()的返回值为math.MaxInt64).

@param limit 单位: B(byte;字节) @return 之前的内存限制

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL