TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Million WebSockets and Go (2017)

210 点作者 riobard超过 5 年前

6 条评论

maxpert超过 5 年前
So some time ago when I was playing around with my toy project (RaspChat) I noticed creating 2 channels and a go routine for every incoming websocket connection is not the answer. I was designing RaspChat to work on a 512MB Raspberry Pi; and I was bottle-necked by GC, and memory consumption around 3 - 4K connections. After loads of optimizations I got it around 5K. Digging deeper and found well I have to maintain a pool of go routines (like threadpool) and I have to write event loop. I was instantly pulling my hair. I was sacrificing so much simplicity, and flexibility of Node.js just because I was trying to avoid event loop and wanted to use channels (I did too much Erlang months before starting project and couldn&#x27;t think anything other than process and messages). I got a backlash on my release (<a href="https:&#x2F;&#x2F;github.com&#x2F;maxpert&#x2F;raspchat&#x2F;releases&#x2F;tag&#x2F;v1.0.0-alpha" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;maxpert&#x2F;raspchat&#x2F;releases&#x2F;tag&#x2F;v1.0.0-alph...</a>) from go community telling me how I was using desierializers&#x2F;leaving loop holes in file upload and I didn&#x27;t know shit about language.<p>At that time I found uws (<a href="https:&#x2F;&#x2F;github.com&#x2F;uNetworking&#x2F;uWebSockets.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;uNetworking&#x2F;uWebSockets.js</a>) that easily got me to 10K easily, and I was like &quot;I would rather bet on a community investing on efficient websocket event loop rather than me writing my own sh*t&quot;. Don&#x27;t get me wrong; I love Golang! Seriously I love it so much I have been pushing my company to use Golang. I just don&#x27;t want to glorify the language for being silver bullet (which it&#x27;s fanboys usually do). I would never implement complicated business logic that involves many moving pieces. When my business requires dealing with shape of an object and mixing matching things to pass data around; I would rather choose a language that lets me deal with shapes of object. Go has it&#x27;s specific use-cases and strengths, people advertising it as move it to go and it would be faster than Java&#x2F;C#&#x2F;Node.js etc. have not done it or have not dealt with complexity of maintaining it.
评论 #21871347 未加载
评论 #21873897 未加载
评论 #21870442 未加载
评论 #21871002 未加载
andrewmatte超过 5 年前
This is still super interesting, two years later but does anyone have an update?<p>Susheel Aroskar, a Netflix engineer, did a talk about push notifications <a href="https:&#x2F;&#x2F;www.infoq.com&#x2F;presentations&#x2F;neflix-push-messaging-scale&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.infoq.com&#x2F;presentations&#x2F;neflix-push-messaging-sc...</a> (2018)
评论 #21867054 未加载
phoboslab超过 5 年前
It&#x27;s surprising to me that you apparently have to fight for memory usage for these cases when using Go.<p>A while ago I ran a (quite naively written) nodejs application that maxed out at ~700k WebSocket connections per server - using only 4GB of RAM. Here CPU became the bottleneck.
评论 #21867738 未加载
评论 #21868398 未加载
评论 #21869021 未加载
jbmsf超过 5 年前
There&#x27;s a brief mention of the load-balancer (nginx) in front of the Go servers; I&#x27;m curious if there&#x27;s anything interesting happening there. I&#x27;d imagine that if you lose a server, all of the clients will try to reconnect and traffic will be spread across the existing servers. That&#x27;s all find and good, but presumably when you bring up a new server to replace the failed on, it&#x27;ll be seriously underutilized. Is there some easy solution here in nginx-land?
评论 #21870116 未加载
fasteo超过 5 年前
For mail.ru, I was expecting [1] you would use tarantool for this task<p>[1]<a href="https:&#x2F;&#x2F;hackernoon.com&#x2F;tarantool-when-it-takes-500-lines-of-code-to-notify-a-million-users-11d340523493" rel="nofollow">https:&#x2F;&#x2F;hackernoon.com&#x2F;tarantool-when-it-takes-500-lines-of-...</a>
maurodelazeri超过 5 年前
nothing beats this <a href="https:&#x2F;&#x2F;github.com&#x2F;uNetworking" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;uNetworking</a>