Go - Should I use it as the only webserver or should it work with a traditional one?

3,868 views
Skip to first unread message

Marcio Andrey Oliveira

unread,
Jan 17, 2014, 8:39:40 AM1/17/14
to golan...@googlegroups.com
Hi.

I started studying Go some days ago and I'm thinking to change my arcade sites infra-structure.

Currently my they are running on PHP (some using Wordpress) + Apache

If my sites were basically serving dynamic pages I would pick just Go. But as they are arcades they serve  tons of images and flash files (bandwidth usage is around 60GB/month).

In this situation where I have many static files (images and flash files) will Go serve this content as fast as Apache / nginx or should I put it behind one of these webservers and let it handle just the generation of dynamic pages?

Thank you all.

Dmitry Vyukov

unread,
Jan 17, 2014, 8:43:58 AM1/17/14
to Marcio Andrey Oliveira, golang-nuts
Go web server can very well serve 25KB/sec and much more.

Dmitry Vyukov

unread,
Jan 17, 2014, 9:20:45 AM1/17/14
to Marcio Andrey Oliveira, golang-nuts
On Fri, Jan 17, 2014 at 6:12 PM, Marcio Andrey Oliveira <plic...@gmail.com> wrote:
Thanks for replying.

So it seems to me that it's better to let Apache / nginx handle static files and and put Go handling just the dynamic pages.

Thanks again.


No, I meant that you can use Go web server to serve both static and dynamic content and simplify your architecture.

25KB/sec is your serving speed (60GB/month).

Go server is only a bit slower than nginx, and I would expect it to easily saturate 1Gbit/sec link.



 

2014/1/17 Dmitry Vyukov <dvy...@google.com>



--
Do you have an arcade site? I do 1:1 Game Exchange

Play free on-line games

Get free games for





Craig Mason-Jones

unread,
Jan 17, 2014, 11:53:35 PM1/17/14
to golan...@googlegroups.com
Go is fast - it will certainly be fast enough to do what you're asking - but it is a little low level.

There are things that Apache and Nginx will do with a little configuration, that you will have to write code to get from Go. For some of these, of course, there are libraries that make it easier, but you'll still have to do it yourself:

  • Logs. You need to configure logging on each route yourself (although Gorilla has some helpful functions).
  • Authentication. If you want basic auth or other types of auth, you'll have to code them yourself in Go.
  • Routing. Different sites off the same server (Gorilla mux makes this easier), or different routes to resources must all be coded.
  • FCGI. At the moment there is no fcgi server library that I know of in Go (net/http/fcgi is for writing clients). If you want to add some other applications (say in PHP), you don't have a common standard for accessing them.
  • Reverse Proxies. This is easy in Apache or Nginx, and in very sophisticated ways, but you would have to write the functions yourself in Go.
  • Server-Status. Both Apache and Nginx server-status integrate nicely with tools like collectd. You might want to write something similar to keep an eye on your server.

These are just off the top of my head.

At a pure performance level, I would imagine a Go webserver could be faster, since it wouldn't have all the configurable goodness I've described above. But both Apache and Nginx are written in C, so they aren't being slowed down by the language: if you were to write a functionally identical webserver in Go, I don't imagine it would be faster.

If performance is an issue, benchmark Apache, Nginx and a bare-bones Go server. I'd love to know your results, but put benchmarks on the web with extreme caution: you'll likely be accused of all sorts of inaccuracies and mistakes ;-) !


All the best,C

Matt Silverlock

unread,
Jan 18, 2014, 2:12:23 AM1/18/14
to golan...@googlegroups.com
Craig makes good points. I'm running a Go server/web app behind a nginx reverse proxy, and I get a lot of "freebies" that are well solved (logging, basic auth, more complete SSL termination/shared caching, etc). The big freebie is also proxy caching, which can increase throughput dramatically. You would have to write a lot of that out in Go, and whilst some of it (logging, basic auth) aren't particularly complex, it's more "reinventing the wheel".

Go is very fast, and I've seen some benchmarks (questionable as they might be) that puts it pretty close to nginx for simple setups. In many cases though, both Go and nginx will rarely be the slow point in your application: chances are you'll either run out of resources on a small VPS first, and/or your database will be the bottleneck.

Marcio Andrey Oliveira

unread,
Jan 18, 2014, 11:36:29 AM1/18/14
to golan...@googlegroups.com
It seems interesting to use either Apache or ngnix with Go but at the moment I don't need neither SSL, nor user authentication.

On the other hand, logging and caching are very important features for me.

Well, I'll have to think very well about which decision to take.


2014/1/18 Matt Silverlock <elit...@gmail.com>

--
You received this message because you are subscribed to a topic in the Google Groups "golang-nuts" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/golang-nuts/moCDscfIc9E/unsubscribe.
To unsubscribe from this group and all its topics, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Do you have an arcade site? I do 1:1 Game Exchange

Play free on-line games

Get free games for




Tamás Gulácsi

unread,
Jan 18, 2014, 12:49:23 PM1/18/14
to golan...@googlegroups.com
You don't really decide: as go performs well over http, you don't need fastcgi, just put a reverse caching proxy before it - if and when you need it.

Caleb Doxsey

unread,
Jan 19, 2014, 9:31:12 AM1/19/14
to Tamás Gulácsi, golang-nuts

For caching you could also use CloudFlare, CloudFront or Google's Page Speed service. These services would be better than rolling your own reverse proxy.

As for logging a systemd init system makes logging a whole lot easier than it used to be. You could wrap https HandleFunc and just log.Println. (probably also want to disable logging timestamps) The OS would handle the rest.

On Jan 18, 2014 10:49 AM, "Tamás Gulácsi" <tgula...@gmail.com> wrote:
You don't really decide: as go performs well over http, you don't need fastcgi, just put a reverse caching proxy before it - if and when you need it.

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.

Matt Silverlock

unread,
Jan 19, 2014, 7:11:27 PM1/19/14
to golan...@googlegroups.com, Tamás Gulácsi, ca...@doxsey.net
CloudFlare is a good option, but it's not free if you want SSL (and in 2014, you should!). At the same time, $20/m isn't too bad if you're running a business.

You'll also need to do a similar amount of work as you would with nginx (proxy caching is about ~12 directives; less if you use defaults) because you may still need to set specific invalidation headers in your app - i.e. https://www.cloudflare.com/docs/client-api.html#s4.5.

As always, horses for courses, but if you're having to set up a server anyway nginx is a) super simple and b) really damned fast. I avoid having to hit my DB cache on every request by "cheating" and using a short (30s) proxy cache via nginx. You can tweak this if your site is more dynamic than mine by either bringing the cache duration down to something like 5s to handle bursts and/or adding a bit of middleware on the routes that you don't want to cache that sets w.Header().Set("Cache-Control", "max-age=0; private; must-revalidate")) on the application side. Note that nginx won't cache anything (by default) that returns a Set-Cookie header either, so user pages won't be cached anyway.

Here's an excerpt from my nginx config for how you would proxy from nginx to Go via HTTP: https://gist.github.com/elithrar/77ee6746104b900e866c

location / {
proxy_pass http://myapp;
proxy_redirect off;
# Security headers removed, but think about X-Frame-Options, Content-Security-Policy, etc
# Enable HTTP keep-alives
proxy_http_version 1.1;
proxy_set_header Connection "";
# Buffers
# Buffers should be greater than the mean response size to allow effective caching
proxy_buffering on;
proxy_buffers 32 16k;
proxy_buffer_size 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
# Caching
# Note that routes with Set-Cookie will not be cached so we do not need to be specific here
add_header Cache-Control "max-age=0, private, must-revalidate";
proxy_cache cache_name;
proxy_cache_key "$scheme$host$request_uri";
proxy_cache_valid 200 302 303 30s;
proxy_cache_valid 404 30s;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
add_header X-Cache $upstream_cache_status;
# Pass scheme and remote host IP to proxied application
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header Referer $http_referer;
proxy_set_header Host $http_host;
}

Feel free to email me/reply here if you have any specific questions. I'm at the tail end of my own Go web project and have spent the last week or so with my head buried in a bunch of Saltstack configs, nginx documentation and wrk benchmarking!

Caleb Doxsey

unread,
Jan 19, 2014, 8:52:15 PM1/19/14
to Matt Silverlock, golang-nuts, Tamás Gulácsi
The reason the services I mentioned are better is because they have full blown CDNs behind them: (https://www.cloudflare.com/features-cdn). Something that you can't achieve with a single nginx install. 

But I suppose that's not super important for most sites, and I agree that having to pay for the SSL isn't fun. I just like to minimize the number of applications in my stack I have to keep track of.
Reply all
Reply to author
Forward
0 new messages