Skip to content

Instantly share code, notes, and snippets.

@benbjohnson
benbjohnson / cpu.svg
Last active August 29, 2015 14:04
ledisdb+bolt cpu pprof w/ NoSync
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@benbjohnson
benbjohnson / README.md
Created August 4, 2014 04:02
Simple Go Deployment on Ubuntu

Steps

  1. Setup Go cross-compile using Dave Cheney's instructions & package.

  2. Copy the myapp.conf file to /etc/init/myapp.conf. Change the name of the service to whatever you want to call it.

  3. Change the name parameter in myapp.conf to your application's name.

  4. Change the script / end script block to whatever you need to startup your app.

package foo
func foo() { kajsd hkasjdh kasjhd aksjhd kasjhd kjahsd kjahsd kajshd kajhsd kasjhd kajshd kajshd kajshd kajshd kasjdh kajshd kasjhd
}
@benbjohnson
benbjohnson / example.go
Last active August 29, 2015 14:03
Go ActiveRecord
package myapp
// Tx represents a transaction in the application.
type Tx struct {
*sql.Tx
}
// User retrieves a user by ID.
func (tx *Tx) User(id int) (*User, error) {
u := &User{tx: tx}
@benbjohnson
benbjohnson / 0_readme.md
Created July 7, 2014 19:28
Bolt error handling

Bolt Error Handling

It's better to simply return the errors that occur from Tx.CreateBucket() and Bucket.Put() because they will rollback the transaction and the error will be returned from DB.Update(). Then you can just check the error from DB.Update().

The DB.Update() can also fail (e.g. the disk write may fail) so you should always check the return error from it.

@benbjohnson
benbjohnson / main.go
Last active August 29, 2015 14:03
flags
package main
import (
"flag"
"log"
"github.com/benbjohnson/myapp"
)
func main() {
# Sequentially insert 1M key/value pairs (in 1000 record batches).
$ bolt bench --count 1000000 --batch-size 1000
# Write 3.939999671s (3.939us/op) (253871 op/sec)
# Read 1.003326413s (40ns/op) (25000000 op/sec)
---------
# Randomly insert 1M key/value pairs (in 1000 record batches).
$ bolt bench --count 1000000 --batch-size 1000 --write-mode rnd
# Write 56.84787703s (56.847us/op) (17591 op/sec)
@benbjohnson
benbjohnson / store.go
Created June 13, 2014 12:04
Session Store Expiration
package store
import (
"fmt"
"github.com/boltdb/bolt"
)
// reap removes sessions older than a given duration.
// This function assumes that all session data is stored in a "sessions" bucket
@benbjohnson
benbjohnson / bench.txt
Created May 22, 2014 13:57
megajson benchmarks
$ go get github.com/benbjohnson/megajson
$ go test -test.bench=. github.com/benbjohnson/megajson/...
BenchmarkScanNumber 50000000 55.3 ns/op 54.25 MB/s
BenchmarkScanString 20000000 95.3 ns/op 104.92 MB/s
BenchmarkScanLongString 5000000 460 ns/op 123.79 MB/s
BenchmarkScanEscapedString 20000000 141 ns/op 127.27 MB/s
BenchmarkReadString 20000000 146 ns/op 68.36 MB/s
BenchmarkReadLongString 5000000 533 ns/op 106.76 MB/s
BenchmarkReadInt 50000000 58.9 ns/op 84.86 MB/s
BenchmarkReadFloat64 10000000 154 ns/op 103.63 MB/s
@benbjohnson
benbjohnson / main.go
Created May 12, 2014 16:37
Bolt for timestamp data
package main
import (
"encoding/binary"
"log"
"time"
"github.com/boltdb/bolt"
)