首页 文章 精选 留言 我的

精选列表

搜索[工作],共10006篇文章
优秀的个人博客,低调大师

处理一次系统假死工作纪实

本文转载自微信公众号「相遇Linux」,作者JeffXie 。转载本文请联系相遇Linux公众号。 最近碰到客户反馈一个问题,系统hang了,ssh登录不上,但是可以ping通,通过串口登录进去之后,敲有些命令会卡住,查看cpu负载内存都很正常,手动触发kdump之后看不出死锁/softlockup/hardlockup等异常状态.而且重要的是已经影响到客户几十亿的业务了。 我能拿到的只有客户提供的vmcore,为了生活而奔波的人儿赶紧分析起来: 系统(SUSE 11SP1) #crash ./vmcore ./vmlinux-2.6.32.59-0.19-default ./vmlinux-2.6.32.59-0.19-default.gz crash>foreach IN bt > inbt 任意找到一个IN(可中断睡眠)的进程 12813 查看堆栈: crash>bt12813 PID:12813TASK:ffff880262eda140CPU:8COMMAND:"sshd" #0[ffff880f98e1ba58]scheduleatffffffff8139d2a4 #1[ffff880f98e1bb10]schedule_timeoutatffffffff8139d935 #2[ffff880f98e1bba0]unix_wait_for_peeratffffffff81376e27 #3[ffff880f98e1bc00]unix_dgram_sendmsgatffffffff813785c2 #4[ffff880f98e1bcb0]sock_sendmsgatffffffff812e8ddc #5[ffff880f98e1be50]sys_sendtoatffffffff812e9318 #6[ffff880f98e1bf80]system_call_fastpathatffffffff81002f7b 汇编unix_dgram_sendmsg() crash>disunix_dgram_sendmsg ... 2410xffffffff813785b7<unix_dgram_sendmsg+1143>:mov%r13,%rsi 2420xffffffff813785ba<unix_dgram_sendmsg+1146>:mov%rbp,%rdi(key1) rdi代表unix_wait_for_peer函数的第一个参数 2430xffffffff813785bd<unix_dgram_sendmsg+1149>:callq0xffffffff81376da0<unix_wait_for_peer> 进程12813 unix_wait_for_peer() 函数的堆栈数据: crash>rd-SSffff880f98e1bba0-effff880f98e1bc00 ffff880f98e1bba0:unix_wait_for_peer+1350000000000000001 ffff880f98e1bbb0:[ffff880262eda140:task_struct]autoremove_wake_function ffff880f98e1bbc0:ffff88021ea8bbc0ffff880238315bc0 ffff880f98e1bbd0:memcpy_fromiovec+87[ffff880238514980:UNIX] ffff880f98e1bbe0:[ffff880238514c30:UNIX][ffff880238514980:UNIX] ffff880f98e1bbf0:[ffff880ff708b630:UNIX]7fffffffffffffff 汇编unix_wait_for_peer() crash>disunix_wait_for_peer 0xffffffff81376da0<unix_wait_for_peer>:sub$0x58,%rsp 0xffffffff81376da4<unix_wait_for_peer+4>:mov$0x1,%edx 0xffffffff81376da9<unix_wait_for_peer+9>:mov%r13,0x50(%rsp) 0xffffffff81376dae<unix_wait_for_peer+14>:lea0x2b8(%rdi),%r13 0xffffffff81376db5<unix_wait_for_peer+21>:mov%rbx,0x38(%rsp) 0xffffffff81376dba<unix_wait_for_peer+26>:mov%gs:0xa580,%rax 0xffffffff81376dc3<unix_wait_for_peer+35>:mov%rax,0x8(%rsp) 0xffffffff81376dc8<unix_wait_for_peer+40>:lea0x18(%rsp),%rax 0xffffffff81376dcd<unix_wait_for_peer+45>:mov%rbp,0x40(%rsp)(key2) rbp压入堆栈(0x58-0x40)处,正好是unix_wait_for_peer堆栈中ffff880f98e1bbe8处,即( [ffff880238514980:UNIX]) 0xffffffff81376dd2<unix_wait_for_peer+50>:mov%rdi,%rbx 0xffffffff81376dd5<unix_wait_for_peer+53>:mov%rsi,%rbp 0xffffffff81376dd8<unix_wait_for_peer+56>:mov%r13,%rdi 查看unix_wait_for_peer()函数源码: 1005staticlongunix_wait_for_peer(structsock*other,longtimeo)(key3) 1006{ 1007structunix_sock*u=unix_sk(other); 1008intsched; 1009DEFINE_WAIT(wait); 1011prepare_to_wait_exclusive(&u->peer_wait,&wait,TASK_INTERRUPTIBLE); .. 1019if(sched) 1020timeo=schedule_timeout(timeo); 1021 1022finish_wait(&u->peer_wait,&wait); 1023returntimeo; 1024} 根据s(key1)(key2)(key3)可以知道12813进程在等待unix_sock(ffff880238514980) crash>structunix_sockffff880238514980|greppeer_wait-A10 peer_wait={ lock={ raw_lock={ slock=3369322707 } }, task_list={ next=0xffff880173427bc0, prev=0xffff8801877a7bc0 } } 查询出这个unix_sock是系统中的/dev/log文件(由syslog-ng创建,系统中大量需要记录log的进程需要通过这个unix_sock与syslog-ng通信,可以参考mansyslog-ng 和/etc/syslog-ng/syslog-ng.conf 配置文件) crash>structunix_sockffff880238514980 ... dentry=0xffff880e7634b9c0, ... crash>structdentry0xffff880e7634b9c0 ... name=0xffff880e7634ba60"log" ... 遍历这个unix_sock的所有等待队列, 说明有645个进程正在等待这个unix_sock(ffff880238514980/dev/log) crash>list__wait_queue.task_list-s__wait_queue.private-H0xffff880173427bc0|grep-iprivate|wc-l 645 所有等待unix_sock的进程重定向到一个wait_unix_sock_process文件 crash>list__wait_queue.task_list-s__wait_queue.private-H0xffff880173427bc0|grep-iprivate>wait_unix_sock_process 查询所有的sshd进程 crash>ps|grepsshd 709716ffff880244cae5c0IN0.0540881392sshd 1281370978ffff880262eda140IN0.0601482900sshd 1905570972ffff880ff74c4200IN0.0601482900sshd 2164270971ffff880262fb4340IN0.0601482904sshd 2195870971ffff880ffab501c0IN0.0601482900sshd 2245970976ffff880ff1ed4100IN0.012105210272sshd 22476224590ffff88022d11a500IN0.01213524552sshd 2333470972ffff880174b04640IN0.0601482900sshd sshd进程大部分都在wait_unix_sock_process文件中,所以ssh登录之后会卡住 查看syslog-ng进程堆栈 crash>bt15232 PID:15232TASK:ffff8801aba90680CPU:6COMMAND:"syslog-ng" #0[ffff88021ea8ba58]scheduleatffffffff8139d2a4 #1[ffff88021ea8bb10]schedule_timeoutatffffffff8139d935 #2[ffff88021ea8bba0]unix_wait_for_peeratffffffff81376e27 #3[ffff88021ea8bc00]unix_dgram_sendmsgatffffffff813785c2 #4[ffff88021ea8bcb0]sock_sendmsgatffffffff812e8ddc #5[ffff88021ea8be50]sys_sendtoatffffffff812e9318 #6[ffff88021ea8bf80]system_call_fastpathatffffffff81002f7b 查看 unix_wait_for_peer()堆栈数据: crash>rd-SSffff88021ea8bba0-effff88021ea8bc00 ffff88021ea8bba0:unix_wait_for_peer+1350000000000000001 ffff88021ea8bbb0:[ffff8801aba90680:task_struct]autoremove_wake_function ffff88021ea8bbc0:ffff880fce8dfbc0ffff880f98e1bbc0 ffff88021ea8bbd0:memcpy_fromiovec+87[ffff880238514980:UNIX] ffff88021ea8bbe0:[ffff880238514c30:UNIX][ffff880238514980:UNIX](key4) ffff88021ea8bbf0:[ffff88104c1c3930:UNIX]7fffffffffffffff 由(key4)可知syslog-ng也是在等待ffff880238514980 unix_sock 所以系统中大量的进程,包括sshd cron等其他的645个进程都在等待unix_sock(/dev/log)(/dev/log由syslog-ng创建),syslog-ng卡住在等这个unix_sock之后,系统中大量的进程都会卡住,包括sshd cron进程等. 但是syslog-ng为什么卡住从vmcore根本看不出来,很可能进程在用户层锁住了. 通过查看客户系统中最近安装的软件发现,他们最近安装了两个定制软件,卸载之后系统恢复正常。 #/bin/rpm-qa--last CARKpam-11.01-1.19TueJun922:49:222020 CARKaim-11.01-1.5TueJun922:38:482020

优秀的个人博客,低调大师

Spring框架里注解@Autowired的工作原理

Suppose I have a bean named HelloWorld which has a member attribute points to another bean User. With annotation @Autowired, as long as getBean is called in the runtime, the returned HelloWorld instance will automatically have user attribute injected with User instance. How is this behavior implemented by Spring framework? (1) in Spring container implementation’s refresh method, all singleton beans will be initialized by default. When the HelloWorld bean is initialized: Since it has the following source code: @Autowired private User user; In the runtime, this annotation is available in metadata via reflection. In metadata structure below, the targetClass points to HelloWorld bean, and injectedElements points to the User class to be injected. (2) In doResolveDependency, the definition for User bean is searched based on this.beanDefinitionNames ( list in DefaultListableBeanFactory ): Once found, the found result is added to array candidateNames: Then the constructor of User bean class is called ( still triggered by getBean call ), the user instance is created by calling constructor: The created user instance together with its name “user” is inserted to the map matchingBeans. Finally the user reference is set to user attribute of HelloWorld instance via reflection. Here the variable bean in line 569 points to HelloWorld instance, and value points to user instance. Once field.set(bean, value) is done, we can observe in debugger that the user attribute in HelloWorld instance is already injected successfully. 本文来自云栖社区合作伙伴“汪子熙”,了解相关信息可以关注微信公众号"汪子熙"。

优秀的个人博客,低调大师

Go 采用 goroutine 和 channel 实现工作池

假设有一组任务需要异步处理且量很大,那我们需要同时开启多个 worker 以保证任务的处理速度而不会堵塞任务。其他语言,可能会需要开启多进程来完成,多进程的控制、IO 消耗等会是个需要注意的问题,而这些 Go 都能帮我们很轻易的解决。 大致的实现要点和流程: 创建2个信道,messages 用于传送任务消息,result 用于接收消息处理结果 创建3个 Worker 协程,用于接收和处理来自 messages 信道的任务消息,并将处理结果通过信道 result 返回 通过信道 messages 发布10条任务 通过信道 result 接收任务处理结果 示例代码: package main import ( "fmt" "strconv" "math/rand" "time" ) type Message struct { Id int Name string } func main() { messages := make(chan Message, 100) result := make(chan error, 100) // 创建任务处理Worker for i := 0; i < 3; i ++ { go worker(i, messages, result) } total := 0 // 发布任务 for k := 1; k <= 10; k ++ { messages <- Message{Id: k, Name: "job" + strconv.Itoa(k)} total += 1 } close(messages) // 接收任务处理结果 for j := 1; j <= total; j ++ { res := <-result if res != nil { fmt.Println(res.Error()) } } close(result) } func worker(worker int, msg <-chan Message, result chan<- error) { // 从通道 chan Message 中监听&接收新的任务 for job := range msg { fmt.Println("worker:", worker, "msg: ", job.Id, ":", job.Name) // 模拟任务执行时间 time.Sleep(time.Second * time.Duration(RandInt(1, 3))) // 通过通道返回执行结果 result <- nil } } func RandInt(min, max int) int { rand.Seed(time.Now().UnixNano()) return min + rand.Intn(max-min+1) } 原文地址: https://shockerli.net/post/golang-worker-pools/

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册