Skip to content

Instantly share code, notes, and snippets.

@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"
--- 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
package main
import (
"io"
"log"
"net/http"
"time"
"github.com/pkg/errors"
"github.com/uber/tchannel-go"
package main
import (
"fmt"
"sync"
"sync/atomic"
"time"
)
func main() {
package main
import (
"sync/atomic"
"testing"
)
func BenchmarkAtomicSerial(b *testing.B) {
var n int64
for i := 0; i < b.N; i++ {

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
> 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
> go test -bench .
goos: darwin
goarch: amd64
pkg: go.uber.org/atomic
BenchmarkStress/u32/std/serial-8 50000000 42.0 ns/op
BenchmarkStress/u32/std/parallel-8 10000000 173 ns/op
BenchmarkStress/u32/serial-8 30000000 42.9 ns/op
BenchmarkStress/u32/parallel-8 10000000 173 ns/op
BenchmarkStress/f64/serial-8 30000000 46.3 ns/op
BenchmarkStress/f64/parallel-8 5000000 359 ns/op
package main
import (
"fmt"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
lumberjack "gopkg.in/natefinch/lumberjack.v2"
"time"
)
2018/12/07 18:19:24 h2c: attempting h2c with prior knowledge.
2018/12/07 18:19:24 http2: server connection from [::1]:43354 on 0xc42008d860
2018/12/07 18:19:24 http2: Framer 0xc4209dc380: wrote SETTINGS len=24, settings: MAX_FRAME_SIZE=1048576, MAX_CONCURRENT_STREAMS=250, MAX_HEADER_LIST_SIZE=1048896, INITIAL_WINDOW_SIZE=1048576
2018/12/07 18:19:24 http2: server: client [::1]:43354 said hello
2018/12/07 18:19:24 http2: Framer 0xc4209dc380: wrote WINDOW_UPDATE len=4 (conn) incr=983041
2018/12/07 18:19:24 http2: Framer 0xc4209dc000: wrote SETTINGS len=0
2018/12/07 18:19:24 http2: Framer 0xc4209dc380: read SETTINGS len=0
2018/12/07 18:19:24 http2: server read frame SETTINGS len=0
2018/12/07 18:19:24 http2: Framer 0xc4209dc380: wrote SETTINGS flags=ACK len=0
2018/12/07 18:19:24 http2: Framer 0xc4209dc000: read SETTINGS len=24, settings: MAX_FRAME_SIZE=1048576, MAX_CONCURRENT_STREAMS=250, MAX_HEADER_LIST_SIZE=1048896, INITIAL_WINDOW_SIZE=1048576