runtime._ExternalCode CPU使用率过高,高达80%
来源:stackoverflow
时间:2024-04-09 21:48:32 346浏览 收藏
珍惜时间,勤奋学习!今天给大家带来《runtime._ExternalCode CPU使用率过高,高达80%》,正文内容主要涉及到等等,如果你正在学习Golang,或者是对Golang有疑问,欢迎大家关注我!后面我会持续更新相关内容的,希望都能帮到正在学习的大家!
我用golang写了一个tcp处理程序,每秒大约300个连接。刚刚投入生产的程序没有任何问题。但运行了大约10天后,我看到cpu使用率高达100%。我使用golang工具“go tool pprof”来获取cpu使用信息:
file: gateway-w type: cpu time: nov 7, 2018 at 5:38pm (cst) duration: 30.14s, total samples = 30.13s ( 100%) entering interactive mode (type "help" for commands, "o" for options) (pprof) top showing nodes accounting for 27.42s, 91.01% of 30.13s total dropped 95 nodes (cum <= 0.15s) showing top 10 nodes out of 28 flat flat% sum% cum cum% 24.69s 81.94% 81.94% 24.69s 81.94% runtime._externalcode /usr/local/go/src/runtime/proc.go 0.57s 1.89% 83.84% 0.57s 1.89% runtime.lock /usr/local/go/src/runtime/lock_futex.go 0.56s 1.86% 85.70% 0.56s 1.86% runtime.unlock /usr/local/go/src/runtime/lock_futex.go 0.26s 0.86% 86.56% 5.37s 17.82% gateway-w/connect/connect-tcp.tcpstartsession /go/src/gateway-w/connect/connect-tcp/tcp_framework.go 0.25s 0.83% 87.39% 1.67s 5.54% net.(*conn).read /usr/local/go/src/net/net.go 0.24s 0.8% 88.18% 1.41s 4.68% net.(*netfd).read /usr/local/go/src/net/fd_unix.go 0.23s 0.76% 88.95% 0.23s 0.76% runtime.nanotime /usr/local/go/src/runtime/sys_linux_amd64.s 0.22s 0.73% 89.68% 0.22s 0.73% internal/poll.(*fdmutex).incref /usr/local/go/src/internal/poll/fd_mutex.go 0.21s 0.7% 90.38% 0.21s 0.7% internal/poll.(*fdmutex).rwunlock /usr/local/go/src/internal/poll/fd_mutex.go 0.19s 0.63% 91.01% 0.19s 0.63% internal/poll.(*fdmutex).rwlock /usr/local/go/src/internal/poll/fd_mutex.go
我的tcphandle代码是这样的:
func tcpstartsession(conn net.conn) { defer closetcp(conn) var (last, n int err error buff []byte ) last, n, err, buff = 0, 0, nil, make([]byte, max_packet_len) for { // set read timeout conn.setreaddeadline(time.now().add(time.duration(tcptimeoutsec) * time.second)) n, err = conn.read(buff[last:]) if err != nil { log.info("tcp read error maybe timeout , ", err) break } if n == 0 { log.debug("empty packet, continue") continue } log.debug("read bytes ", n) log.info("get a raw package:", hex.encodetostring(buff[:last+n])) last += n ... for { if last == 0 { break } ret, err := protohandle.iswhole(buff[:last]) if err != nil { log.warn("proto handle check iswhole error", err) } log.debug("rest buffer len = %d\n", ret) if ret < 0 { //wait for more tcp fragment. break } packetlen := last - ret packetbuf := make([]byte, packetlen) copy(packetbuf, buff[:packetlen]) last = ret if last > 0 { copy(buff, buff[packetlen:packetlen+last]) } ... } } }
我无法理解runtime._externalcode 的含义。这是golang内部的函数。
我的golang版本是:go版本go1.9.2 linux/amd64
我的程序正在docker上运行
my docker version is : 1.12.6
我希望有人能帮助我。非常感谢!
我尝试将golang版本升级到1.10.3。运行了半年多,没有出现任何问题。最近也出现了同样的问题,不过我没有改程序代码。我怀疑这段代码有问题:
conn.SetReadDeadline(time.Now().Add(time.Duration(tcpTimeOutSec) * time.Second))
需要您的帮助,谢谢。
解决方案
正如您已确认您的程序不是使用 CGO_ENABLED=0 构建的
问题(可能)出在程序的 C go 部分。 pprof 无法分析 C 库的内部部分
我相信还有一些其他东西可以算作“_External”,比如时间。现在在某些系统上
好了,本文到此结束,带大家了解了《runtime._ExternalCode CPU使用率过高,高达80%》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!
-
502 收藏
-
502 收藏
-
501 收藏
-
501 收藏
-
501 收藏
-
139 收藏
-
204 收藏
-
325 收藏
-
477 收藏
-
486 收藏
-
439 收藏
-
357 收藏
-
352 收藏
-
101 收藏
-
440 收藏
-
212 收藏
-
143 收藏
-
- 前端进阶之JavaScript设计模式
- 设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
- 立即学习 542次学习
-
- GO语言核心编程课程
- 本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
- 立即学习 508次学习
-
- 简单聊聊mysql8与网络通信
- 如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
- 立即学习 497次学习
-
- JavaScript正则表达式基础与实战
- 在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
- 立即学习 487次学习
-
- 从零制作响应式网站—Grid布局
- 本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
- 立即学习 484次学习