Live data from Hacker News

I rewrote my blog in Go

ironzebra.com

71–77 of 77 posts

Re: I rewrote my blog in Go

#71
post #44

I built a small site in Go and I didn't really see the need to use a framework. Here's what I did for routes. func getRoutes() map[string]customHndlrFnc { r := make(map[string]customHndlrFnc) //routes r["/route_to_url"] = handler r["/route_to_url2"] = handler2 return r } for key, value := range getRoutes() { http.HandleFunc(key, handlerWrapper(value)) } All of my routes for this sample were get requests but it could…

Why do that versus:

  http.HandleFunc("/route_to_url", handlerWrapper(handler))
  http.HandleFunc("/route_to_url2", handlerWrapper(handler2))
Is the map used elsewhere?

Re: I rewrote my blog in Go

#72
post #6

How did you achieve a 16 second response time for your blog ? What the heck were you doing?

Yeah, it's not surprising that any change would make it faster. Plot twist: OP was previously typing the server response BY HAND.

Those cookies can be a real pain if you make a typo.

Re: I rewrote my blog in Go

#73
post #68
post #46

Earlier quoted context omitted.

Is this true? I'm not sure about C, but it's definitely the case that Go compiles magnitudes faster than C++, for any reasonable sized project. For example, the ~200k lines of Go standard library compiles in about 14 seconds on my workstation, while random C++ libraries frequently take much longer (just my anecdotal impression from waiting on "brew install").

C++ compiles pretty slow due to templates being in the header files, and the need to re-parse them in every compilation unit. Also the language is quite complex and requires multiple analyses at parse time to decide what the developer is really trying to do. C code can be compiled fast if not many optimizations are being made. For example the Tiny C compiler was compiling the Linux kernel around 15s in 2004, not sure…

The slowness of C++ compilation is more complicated than you imply. Walter Bright details the causes here: http://www.drdobbs.com/228701711

Re: I rewrote my blog in Go

#74
post #68

Earlier quoted context omitted.

C++ compiles pretty slow due to templates being in the header files, and the need to re-parse them in every compilation unit. Also the language is quite complex and requires multiple analyses at parse time to decide what the developer is really trying to do. C code can be compiled fast if not many optimizations are being made. For example the Tiny C compiler was compiling the Linux kernel around 15s in 2004, not sure…

The slowness of C++ compilation is more complicated than you imply. Walter Bright details the causes here: http://www.drdobbs.com/228701711

I know, but that is why Walter's information is an article and not a plain simple post. There is too much compiler related information to discuss.

Re: I rewrote my blog in Go

#75
post #63

Earlier quoted context omitted.

It uses exactly as much memory as you specify. It would be pretty stupid to have plenty of RAM and NOT using it. With enough memory GC becomes essentially free, by not having to do any work.

Nonsense. I'm talking about the SAME data taking more memory to represent. Plus, all things being equal a larger memory space will take more time to GC, and GCs become longer, not shorter. The JVM does things suboptimally in a number of ways. Object memory overhead is relatively high - typically 8 or 16 bytes per object, strings as UTF-16 (vs Go's UTF-8), etc. It really adds up, and funtional languages tend to churn…

Wrong, wrong, wrong and wrong.

Re: I rewrote my blog in Go

#76
post #28

Earlier quoted context omitted.

Save yourself the pain and go with Scala and the JVM ... mature platform with battle tested GCs, all the libraries and concurrency idioms you'll ever need and a modern FP language designed for scale.

Only if you don't mind paying approximately an order of magnitude penalty in RAM usage, which has long been an achilles heel of JVM languages. http://benchmarksgame.alioth.debian.org/u64/benchmark.php?te...

In a server-side context the JVM tends to be the most memory efficient out of all platforms that make use of GC. Here's for example the comparison of Ruby MRI with JRuby, showing a massive difference in memory usage, and yet many Ruby developers choose to deploy their apps on top of JRuby precisely because of much better memory usage, which is why your reference to these benchmarks is basically useless:

http://benchmarksgame.alioth.debian.org/u64/benchmark.php?te...

Re: I rewrote my blog in Go

#77
post #63

Earlier quoted context omitted.

It uses exactly as much memory as you specify. It would be pretty stupid to have plenty of RAM and NOT using it. With enough memory GC becomes essentially free, by not having to do any work.

Nonsense. I'm talking about the SAME data taking more memory to represent. Plus, all things being equal a larger memory space will take more time to GC, and GCs become longer, not shorter. The JVM does things suboptimally in a number of ways. Object memory overhead is relatively high - typically 8 or 16 bytes per object, strings as UTF-16 (vs Go's UTF-8), etc. It really adds up, and funtional languages tend to churn…

This is the first time I ever heard anybody complain about UTF-16, citing it as the reason for why the JVM consumes more memory, which is of course bullshit.

One reason for why JVM apps appear to consume so much memory is because the JVM allocates more memory than it needs. It does so because the garbage collectors are generational and compacting (well, CMS is non-compacting, but when the memory gets too fragmented, the VM does fallback to a stop-the-world compaction of memory). In a server context the JVM also does not release the free memory it has to the operating system, because allocating that memory in the first place is expensive and so it keeps it for later usage ... the result is that memory allocation on top of the JVM is as efficient as stack allocation, since all the JVM does is to increment a pointer, and deallocation of short-lived objects is nearly as innexpensive as stack unwinding, since the GC is generational and deallocates stuff in bulk. These capabilities come at a cost, as the GC also needs memory to move things around, but it's also memory well spent (e.g. Firefox has been plagued by memory fragmentation for years).

Speaking of Golang, it has some of the shittiest GCs in existence ... non-generational, non-compacting, non-concurrent and "mostly precise". Of course, it used to be fully conservative, which meant you could easily end up with really nasty memory leaks on 32bits systems, because the GC wasn't able to make a difference between Ints and pointers.

The only thing saving Go is the ability to work in many cases with the stack, alleviating the stress that the GC faces, but this low-level capability will also prevent it from having a good GC anytime soon, like the JVM has had for years.

And really, in terms of memory usage, you should see how the JVM's CMS or G1 behaves in production, as it makes all the difference. Our web-service (written in Scala) that's being hit by more than 30,000 requests per second that must be served in under 100ms per request, was at some point hosted on Heroku, using only 8 instances, instances which have less than 400 MB of usable RAM. It was absolutely superb seeing it in action, as the processes themselves were not exceeding 200 MB of real usage - Heroku even told us that we are costing them more than we are paying them.

So yeah, you can talk bullshit about strings being UTF-16, but the real wold disagrees.

Post reply on HN