Skip to content

Instantly share code, notes, and snippets.

> go test -bench . -benchmem
goos: darwin
goarch: amd64
pkg: go.uber.org/atomic
BenchmarkStress/u64/serial-8 30000000 41.7 ns/op 0 B/op 0 allocs/op
BenchmarkStress/u64/parallel-8 10000000 169 ns/op 0 B/op 0 allocs/op
BenchmarkStress/f64/serial-8 30000000 45.9 ns/op 0 B/op 0 allocs/op
BenchmarkStress/f64/parallel-8 5000000 362 ns/op 0 B/op 0 allocs/op
BenchmarkStress/bool/serial-8 50000000 38.4 ns/op 0 B/op 0 allocs/op
BenchmarkStress/bool/parallel-8 10000000 157 ns/op 0 B/op 0 allocs/op

golang.org rate limiter:

	rl := rate.NewLimiter(1000000, 1)
 
	last := time.Now()
	for i := 0; i < 10; i++ {
		rl.Wait(context.Background())
		cur := time.Now()
		fmt.Println("last", cur.Sub(last))
 last = cur
package main
import (
"sync/atomic"
"testing"
)
func BenchmarkAtomicSerial(b *testing.B) {
var n int64
for i := 0; i < b.N; i++ {
package main
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
func main() {
package main
import (
"io"
"log"
"net/http"
"time"
"github.com/pkg/errors"
"github.com/uber/tchannel-go"
--- FAIL: TestNoTimeout (0.02s)
<autogenerated>:31: Unexpected log: [Warn]: Failed to add connection to peer [{service relay} {process relay-58154} {hostPort 127.0.0.1:58154} {connID 370} {localAddr 127.0.0.1:58154} {remoteAddr 127.0.0.1:60664} {remoteHostPort 127.0.0.1:56950} {direction inbound} {error tchannel error ErrCodeNetwork: connection is in an invalid state}]
<autogenerated>:29: Debug logs:
01:01:13.311964 [D] NewChannel created at goroutine 1689 [running]:
github.com/uber/tchannel-go.getStacks(0xc82071d300, 0x0, 0x0, 0x0)
/home/travis/gopath/src/github.com/uber/tchannel-go/introspection.go:392 +0xb9
github.com/uber/tchannel-go.registerNewChannel(0xc82071d320)
/home/travis/gopath/src/github.com/uber/tchannel-go/all_channels.go:36 +0x61
github.com/uber/tchannel-go.NewChannel(0xbd29a0, 0xb, 0xc822546a00, 0xbbaa40, 0x0, 0x0)
/home/travis/gopath/src/github.com/uber/tchannel-go/channel.go:234 +0xf89
@prashantv
prashantv / tchannel-migrate.sh
Last active October 6, 2015 00:49
Migrate TChannel clients from the old import (github.com/uber/tchannel/golang) to the new import (github.com/uber/tchannel-go)
# Get the new tchannel-go repository.
go get -f -u github.com/uber/tchannel-go
# Delete the old tchannel repository to avoid goimports importing it.
rm -rf ${GOPATH}/src/github.com/uber/tchannel
# Rewrite all imports to use the new repository.
for f in `grep --include '*.go' --exclude-dir "Godeps" --exclude-dir "thrift-binaries" --exclude-dir "build_test" "tchannel/golang" -R -l .`
do
echo "Rewriting $f"