systemd forking

blov · · 655 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m using Go to handle websockets. It&#39;s started with systemd as:</p> <pre><code>[Unit] Description=ODC websocket binary in Go Requires=vagrant.mount After=network.target vagrant.mount [Service] Type=simple ExecStart=/vagrant/go/bin/odc Restart=on-abort [Install] WantedBy=multi-user.target vagrant.mount </code></pre> <p>After awhile, I can see that 6 of these processes are now running. Because of Go&#39;s baked in concurrency, I&#39;m guessing this is a bad thing, especially if all these processes want to respond to the same port?</p> <p>Does anyone else have this issue, or is it not really an issue at all?</p> <hr/>**评论:**<br/><br/>pdffs: <pre><p>How are you seeing that 6 processes are running? Do they actually have the same PID? If so, you&#39;re just seeing threads, not separate processes.</p></pre>asdf072: <pre><p>That&#39;s what I was thinking, but they each have their own PID. However, if I use htop and group them, they all fall under what looks like a master process, so I think they are go concurrency at work. Like you said, I didn&#39;t think they&#39;d have separate PID&#39;s.</p></pre>st3fan: <pre><p>Threads also have a pid. Htop will show threads in green. If that is hard to see, enable the TGID column, which should be the PID of the process that owns the thread.</p></pre>CrackerJackMack: <pre><p>This is not a systemd issue or even an issue at all I don&#39;t believe. Go spawns <a href="https://rakyll.org/scheduler/" rel="nofollow">multiple threads to &#34;balance&#34;</a> work across multiple cores. When you do <code>systemctl status odc.service</code> you should see one parent process (bottom) and 5 children (above).</p> <p>Even if you didn&#39;t stop your main() from exiting the Restart=on-abort shouldn&#39;t spawn perpetually. on-failure is typically the desired setting.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

655 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传