Golang内存占用检测

Golang 内存占用检测 参考链接 https://lrita.github.io/2017/05/26/golang-memory-pprof/ 涉及命令 go tool pprof http://{host}/debug/pprof/heap 缘由 同样的服务在上了多组服务器后监控显示内存 process_resident_memory_bytes 区别很大,多组服务会根据实际连接和用户情况增减,但有一组数值仍然居高不下,数据对比就是20+M和50+M。以下便找出两台作为对比定位原因。{host1}为需要检测的服务。 命令使用 通过 go tool pprof http://{host}/debug/pprof/heap 进入查看命令行,直接输入 top 后 [WenpiCai@LOCAL-192-168-97-55 ~]$ go tool pprof http://{host1}/debug/pprof/heap Fetching profile over HTTP from http://{host1}/debug/pprof/heap Saved profile in /home/WenpiCai/pprof/pprof.MoziGateA.alloc_objects.alloc_space.inuse_objects.inuse_space.006.pb.gz File: MoziGateA Type: inuse_space Time: Jan 14, 2021 at 10:26am (CST) Entering interactive mode (type "help" for commands, "o" for options) (pprof) top Showing nodes accounting for 5524.47kB, 100% of 5524.47kB total Showing top 10 nodes out of 41 flat flat% sum% cum cum% 1542.
Read more →

小游戏重构之路

Read more →

Goroutine请求TCP返回读取问题

Read more →

Golang指定时区

Read more →

Golang信号发送与接收

Read more →

记goroutine泄露

程序说明 监听 TCP 与 UDP 服务,TCP 服务保持客户端长连接,UDP 服务由业务端调用发消息到客户端。 发现问题 通过监控系统发现 goroutine 数量居高不下,正常情况下是一个用户一个 goroutine 才是,明显出现了异常情况。 定位问题 这种情况应该是次 goroutine 泄露现象,需要知道哪个位置导致的。 初步猜测 TCP 连接断开重连导致,翻看日志,看到存在很多高频率重连,只是不符合导致暴涨现象。 回头直接看 goroutine 占用情况,方式 https://caiwp.github.io/post/golang利用pprof定位问题/ 原因也就一目了然,是 UDP 服务发全服消息时调用的 goroutine 无法执行结束。 上代码 // Handle 执行 func (t *UdpTransport) Handle(ctx context.Context, addr net.Addr, reader *Reader) { ctx, cancel := context.WithTimeout(ctx, 5*time.Second) defer cancel() ch := make(chan struct{}, 0) go func() { t.run(ctx, addr, reader) ch <- struct{}{} // ERROR 会堵在这 }() select { case <-ch: case <-ctx.
Read more →

Golang整数范围

参考链接 https://stackoverflow.com/questions/6878590/the-maximum-value-for-an-int-type-in-go https://groups.google.com/group/golang-nuts/msg/71c307e4d73024ce?pli=1 The germane part: Since integer types use two’s complement arithmetic, you can infer the min/max constant values for int and uint. For example, > const MaxUint = ^uint(0) > const MinUint = 0 > const MaxInt = int(MaxUint >> 1) > const MinInt = -MaxInt - 1 > As per @CarelZA's comment: golang uint8 : 0 to 255 uint16 : 0 to 65535 uint32 : 0 to 4294967295 uint64 : 0 to 18446744073709551615 int8 : -128 to 127 int16 : -32768 to 32767 int32 : -2147483648 to 2147483647 int64 : -9223372036854775808 to 9223372036854775807
Read more →

Golang数组复制

Read more →

Go比较float

Read more →

Golang 利用 pprof 定位问题

Read more →