Quick question for those that are well versed using Node and Golang and can offer a good comparison

polaris · · 591 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m mainly wondering, at what points in making a web app, does golang surpass node, I have been using Go for a while now but to be honest I enjoy writing Javascript more than golang so I tend to pick Node for most things, when I have something I need high concurrency on I make a websocket server with golang and just connect to that, but my main question is:</p> <p>At what point in a web app does golang surpass node. Thanks.</p> <hr/>**评论:**<br/><br/>tjholowaychuk: <pre><p>IMO anything you want to be reasonably confident in, Go would be a better fit. Go in some cases may be a bit more verbose or require a bit of extra code but it&#39;s worth it. Namely error handling and just general robustness due to static typing etc. Go&#39;s streams via reader/writers are also much nicer than Node&#39;s.</p> <p>The only things I would say Node maybe excels at is a) JSON parsing speed (v8 is fast here, Go is slow when the input is arbitrary), working with arbitrary objects (bit painful with Go, but rarely necessary). That&#39;s really about it from my experience with the two. </p> <p>While working with Node in production I&#39;ve seen a number of cases where a single bug takes down the entire application, only to restart and crash again moments later. This sort of thrashing is pretty bad with Node, thankfully similar is usually isolated in Go, even if Go isn&#39;t perfect in that respect. So I think it depends on how important your project is! Node may be quicker to bootstrap in some cases but yeah.</p></pre>lex99: <pre><p>Well, Node is web-scale, so there&#39;s that....</p> <p>&lt;/s&gt;</p> <p>But seriously, your question is too general. Golang is great for some web apps, sucks for others. If you want an end-to-end framework with a lot of convention and tons of usage/contributors, you might be better off with node or even Ruby. The web framework world in golang is still kinda iffy. That said, I personally don&#39;t like the loosey-goosiness of JS, and I think grunt and node_modules suck, but YMMV. Good luck!</p></pre>Gacnt: <pre><p>Web-scale?</p></pre>pierrrre: <pre><p><a href="https://www.youtube.com/watch?v=bzkRVzciAZg" rel="nofollow">https://www.youtube.com/watch?v=bzkRVzciAZg</a></p> <p>or <a href="https://www.youtube.com/watch?v=b2F-DItXtZs" rel="nofollow">https://www.youtube.com/watch?v=b2F-DItXtZs</a></p></pre>kl0nos: <pre><p>I am using both. I can tell you from my experience that because node is javascript = dynamically typed you need to watch a lot more than in Go which is typed language, but on the other side thanks to this you are more productive in node. Another thing that is important is concurrency, Go is a clear winner here thanks to channels, wait groups, mutexes. In node in complex situation where you have a LOT of async IO from which you need results and make more IO, where you have multi level nested situations, then even if you use library like async your code will look not very clear, you will have innercallbacks, outercallbacks etc.</p> <p>For your problem i would use Go any day, while node looks good on benchmarks with WebSockets, the truth is that it only looks well on maintaining a lot of idle connections but when you start sending data over those websocket channels you will see it&#39;s not so great, compare it with Go and you will see that latency/performance wise Go will be better choice.</p></pre>i_regret_most_of_it: <pre><p>If you prefer node, and you&#39;re also proficient at writing reliable node programs ... and you have a lot of frontend work (forms, templating, asset pipeline etc), node tends to be the winner, thanks to the ecosystem. Concrete example: server side rendering of React components. Any Go solution is ... ugh.</p> <p>For purely backend stuff (no need for dom or leveraging frontend technologies), I think Go is superior in every way.</p> <p>Edit: cut out pointless rant about node</p></pre>mc_hammerd: <pre><p><a href="https://www.techempower.com/benchmarks/" rel="nofollow">https://www.techempower.com/benchmarks/</a></p> <p>these were the benchmarks that convinced me to learn go and node. back in the day go and node were top 4 only behind openresty and java servelets...</p> <p>tbh go wins some benchmarks and node wins some benchmarks, <em>i would use whatever you want</em>.</p></pre>Gacnt: <pre><p>I don&#39;t know how I feel about the multiple queries benchmark, go is so low on the list I feel like if they had multiple queeries there weren&#39;t using any sort of concurrency method and just had 20 in a row synchronously. I can&#39;t imagine 20 go routines with a channel receiving taking that long to do 20 queries</p></pre>

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

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