Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.
Rewriting a blog in Go
Streamlining from Django to Go
My background
PHP
JavaScript
CSS
Java
C++
Python Node.js Go →
A bit about Go
➔ Syntax somewhere between Python and
Java
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")...
A bit about Go
➔ Compiled language
➔ Statically typed, but not stupid:
var hello string = “hi there” // valid
greeting := ...
A bit about Go
➔ Very opinionated...
$ go fmt yourcode.go
$ go get github.com/hermanschaaf/ironzebra
...and that’s a good ...
➔ Learning & Fun
➔ The “Hello World” of web applications
➔ I did the same thing in Django
➔ The Django blog was reaaally s...
What I want
➔ Markdown
➔ MongoDB
➔ Admin Login
➔ Faster load times
What I go get
➔ Markdown (github.com/russross/blackfriday)
➔ MongoDB (labix.org/v2/mgo)
➔ Admin Login (code.google.com/p/g...
Markdown: blackfriday
$ go get github.com/russross/blackfriday
import "github.com/russross/blackfriday"
// markdown string...
MongoDB: mgo
➔ mgo is a great wrapper for MongoDB
func getPosts(c Blog) ([]models.Post) (postList []
models.Post{}) {
coll...
MongoDB: mgo
➔ ...but had some surprises:
collection.Find(
bson.M{"title": title}).One(&result)
Faster load times: Revel
http://www.techempower.com/benchmarks/#section=data-r5&hw=i7&test=db&o=5&f=1elc8-9fm70g-0
Revel
➔ MVC framework
➔ Still in pre-1.0 release
➔ Offers routing, parameter parsing, validation,
session/flash, templatin...
Revel
➔ Really nice routing:
GET / App.Index
GET /posts/ Blog.List
GET /:category/:id/:slugString Blog.Show
➔ Useful contr...
Revel
➔ Go’s built-in templates aren’t so great
[[--- show.html ---]]
{{set . "title" .result.Title}}
{{template "header.h...
The Results
Time Googlebot spent downloading the HTML text only
BUT!!
➔ This was not a scientific experiment:
◆ Moved server to Heroku (git deploy!)
◆ Trimmed down the HTML, removed some...
Conclusions
➔ Site loading at least 10x faster
➔ Same amount of effort as Django, or less
➔ “Hello World” of web applicati...
I no longer fear the HN frontpage
Nächste SlideShare
Wird geladen in …5
×

I rewrote my blog in Go

4.502 Aufrufe

Veröffentlicht am

A summary of my experiences in rewriting the IronZebra blog from Django to Go. For the original HN front-page blog post, see http://www.ironzebra.com/code/103/i-rewrote-my-blog-in-go

Veröffentlicht in: Technologie
  • Als Erste(r) kommentieren

I rewrote my blog in Go

  1. 1. Rewriting a blog in Go Streamlining from Django to Go
  2. 2. My background PHP JavaScript CSS Java C++ Python Node.js Go →
  3. 3. A bit about Go ➔ Syntax somewhere between Python and Java package main import "fmt" func main() { fmt.Println("Hello, 世界") }
  4. 4. A bit about Go ➔ Compiled language ➔ Statically typed, but not stupid: var hello string = “hi there” // valid greeting := “how are you” // also valid ➔ Good compromise between ease of development and efficiency
  5. 5. A bit about Go ➔ Very opinionated... $ go fmt yourcode.go $ go get github.com/hermanschaaf/ironzebra ...and that’s a good thing
  6. 6. ➔ Learning & Fun ➔ The “Hello World” of web applications ➔ I did the same thing in Django ➔ The Django blog was reaaally sloooooow ➔ Fear of landing on HN front page (really!) Reasons for rewriting my blog
  7. 7. What I want ➔ Markdown ➔ MongoDB ➔ Admin Login ➔ Faster load times
  8. 8. What I go get ➔ Markdown (github.com/russross/blackfriday) ➔ MongoDB (labix.org/v2/mgo) ➔ Admin Login (code.google.com/p/go.crypto/bcrypt) ➔ Faster load times (github.com/robfig/revel)
  9. 9. Markdown: blackfriday $ go get github.com/russross/blackfriday import "github.com/russross/blackfriday" // markdown string body := “Hello, _markdown_, my old *friend*.” // parse markdown into HTML string html := string(blackfriday.MarkdownCommon([]byte (body)))
  10. 10. MongoDB: mgo ➔ mgo is a great wrapper for MongoDB func getPosts(c Blog) ([]models.Post) (postList [] models.Post{}) { collection := c.Database.C("posts") query := bson.M{"published": true} q := collection.Find(query).Sort("-timestamp") q.Limit(10).Iter().All(&postList) }
  11. 11. MongoDB: mgo ➔ ...but had some surprises: collection.Find( bson.M{"title": title}).One(&result)
  12. 12. Faster load times: Revel http://www.techempower.com/benchmarks/#section=data-r5&hw=i7&test=db&o=5&f=1elc8-9fm70g-0
  13. 13. Revel ➔ MVC framework ➔ Still in pre-1.0 release ➔ Offers routing, parameter parsing, validation, session/flash, templating, caching, job running, testing, and even i18n
  14. 14. Revel ➔ Really nice routing: GET / App.Index GET /posts/ Blog.List GET /:category/:id/:slugString Blog.Show ➔ Useful controller hooks ➔ Each http request gets separate goroutine
  15. 15. Revel ➔ Go’s built-in templates aren’t so great [[--- show.html ---]] {{set . "title" .result.Title}} {{template "header.html" .}} </head> {{template "post.html" .}} {{ .html_output }}
  16. 16. The Results Time Googlebot spent downloading the HTML text only
  17. 17. BUT!! ➔ This was not a scientific experiment: ◆ Moved server to Heroku (git deploy!) ◆ Trimmed down the HTML, removed some queries ◆ Database used to be on same machine, now hosted on Mongolab
  18. 18. Conclusions ➔ Site loading at least 10x faster ➔ Same amount of effort as Django, or less ➔ “Hello World” of web applications: Proof of concept of what can be done when not even trying very hard
  19. 19. I no longer fear the HN frontpage

×