Newbie question: How does a golang server compare to NGINX and Apache?

agolangf · · 319 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I used Apache in the past, for hosting PHP websites. I know very little about NGINX but from what I understand it&#39;s also a web/mail server. </p> <p>How do most developers use Go on the server, do they install the web server software together with the Go program, or do they use the stdlib http/smtp server? </p> <p>What are the pros and cons of using full web servers like Apache and using only the Go libraries?</p> <hr/>**评论:**<br/><br/>justinisrael: <pre><blockquote> <p>I used Apache in the past, for hosting PHP websites. I know very little about NGINX but from what I understand it&#39;s also a web/mail server. </p> </blockquote> <p>Nginx uses an asynchronous model for serving requests which gives it better performance than Apache for certain use cases. It has historically had extremely good capabilities for serving static content, or tons of connections without the memory overhead of tons of threads to service them. </p> <blockquote> <p>How do most developers use Go on the server, do they install the web server software together with the Go program, or do they use the stdlib http/smtp server? </p> </blockquote> <p>Go has a stdlib which contains a production grade net package. It can be used directly as a web server without the need for a reverse proxy. That is, many people simply copy a binary to a server and start it on a port. But others may have reasons for putting a Go server behind a reverse proxy (Apache, nginx, Caddy) </p> <blockquote> <p>What are the pros and cons of using full web servers like Apache and using only the Go libraries?</p> </blockquote> <p>A Go binary can be a full web server on its own without Apache. But if you need to proxy requests to different applications, then maybe a dedicated web server like Apache, nginx, caddy, or other may be desirable to you. Maybe a particular server has very good caching and serving of static content. Or you want to use a load balancer in front of multiple instances of a server. Or you want to handle authentication or encryption before your Go application. </p></pre>DanChm: <pre><p>Thanks, this is great. Cleared things up.</p></pre>thewhitetulip: <pre><p>If you want to learn how to write webapps in Go without using a web framework, you might like reading this tutorial(which I wrote), <a href="http://github.com/thewhitetulip/web-dev-golang-anti-textbook" rel="nofollow">http://github.com/thewhitetulip/web-dev-golang-anti-textbook</a></p> <p>http is built into the language and it is an amazing package, hence no framework needed. All you need are a collection of libraries.</p></pre>DocMerlin: <pre><p>Its nearly always faster if using to to NOT use NGINX or Apache along with go. Even if just using it as an SSL terminator, NGINX + Go has a roughly 30% overhead compared to just Go. Apache&#39;s numbers are even worse.</p> <p>However, if you are just trying to serve files or do something where you do not need the Go app layer at all, just use NGINX, its faster by itself than the Go app is by itself.</p> <p>TL;DR: Use Only Go is better than NGINX+GO. Only NGINX is better than only Go.</p></pre>fortytw2: <pre><p>I benchmarked this a few days ago, <a href="https://github.com/fortytw2/dirty-ssl-bench" rel="nofollow">https://github.com/fortytw2/dirty-ssl-bench</a> (may be some issues with the bench, as a few people have pointed out, too low load and not using keep-alive between nginx and go), but I think it&#39;s mostly accurate </p></pre>

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

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