Skip to content

Instantly share code, notes, and snippets.

@benbjohnson
benbjohnson / race.txt
Created April 29, 2014 22:04
hashicorp/raft: race detection
$ go test -v -race
=== RUN TestFileSnapshotStoreImpl
--- PASS: TestFileSnapshotStoreImpl (0.00 seconds)
=== RUN TestFileSnapshotSinkImpl
--- PASS: TestFileSnapshotSinkImpl (0.00 seconds)
=== RUN TestFileSS_CreateSnapshot
2014/04/29 16:03:28 [INFO] snapshot: Creating new snapshot at /var/folders/p3/nqt2bgp17fn7_t9hr6tr_1m00000gn/T/raft166453656/snapshots/3-10-2014-04-29T16:03:28.194235901-06:00.tmp
2014/04/29 16:03:28 [WARN] snapshot: Found temporary snapshot: 3-10-2014-04-29T16:03:28.194235901-06:00.tmp
--- PASS: TestFileSS_CreateSnapshot (0.00 seconds)
=== RUN TestFileSS_CancelSnapshot
@benbjohnson
benbjohnson / golint.txt
Created April 29, 2014 22:10
hashicorp/raft: golint
$ golint .
commands.go:3:6: exported type AppendEntriesRequest should have comment or be unexported
commands.go:19:6: exported type AppendEntriesResponse should have comment or be unexported
commands.go:30:6: exported type RequestVoteRequest should have comment or be unexported
commands.go:40:6: exported type RequestVoteResponse should have comment or be unexported
commands.go:51:6: exported type InstallSnapshotRequest should have comment or be unexported
commands.go:66:6: exported type InstallSnapshotResponse should have comment or be unexported
config.go:64:1: exported function DefaultConfig should have comment or be unexported
file_snapshot.go:38:1: comment on exported type FileSnapshotSink should be of the form "FileSnapshotSink ..." (with optional leading article)
file_snapshot.go:191:1: exported method FileSnapshotStore.List should have comment or be unexported
@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
# 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 / main.go
Last active August 29, 2015 14:03
flags
package main
import (
"flag"
"log"
"github.com/benbjohnson/myapp"
)
func main() {
@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 / 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}
package foo
func foo() { kajsd hkasjdh kasjhd aksjhd kasjhd kjahsd kjahsd kajshd kajhsd kasjhd kajshd kajshd kajshd kajshd kasjdh kajshd kasjhd
}
@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 / cpu.svg
Created August 6, 2014 14:45
ledisdb+bolt cpu pprof w/o NoSync
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.