三、七牛老许

qlang: github qiniu/qlang

microservice architecture: http://martinfowler.com/articles/microservices.html

Service Governance

  • Authorization
  • Logging
  • Change management
  • Central configuration
  • Scale in and scale out
  • Overload Protection
  • Service degradation
  • Monitor performance and health
  • Manage how and by whom services are used
  • Topology discovery and failure recovery

Overload Protection

  • N = Alert threshold
  • Important things
  • keep limit to N*2,not N
  • kill slow requests(SLA)

四、Dave Cheney 澳洲golang社区负责人,运行悉尼go用户组

http://dave.cheney.net/

Further reading: runtime/pprof

Further reading: Google Perf Tools

  • pprof

-memprofilerate=N adjusts the profile rate to 1/N

#visualise mem profile
go build -gcflags='-memprofile=/tmp/m.p'
go tool pprof --alloc_objects -svg $(go tool -n compile) /tmp/m.p > alloc_objects.svg
go tool pprof --inuse_objects -svg $(go tool -n compile) /tmp/m.p > alloc_objects.svg
  • benchmarking
#fib.go:
func Fib(n int) int {
if n<2 {
return n
}
return Fib(n-1)+Fib(n-2)
}
#fib_test.go:
import "testing"
func BenchmarkFib(b *testing.B) {
for n:=0;n<b.N;n++ {
Fib(20)
}
}
#go test -bench=. ./fib
    • do benchmark multiple times or use "-count=" flag
    • tools like rsc.io/benchstat are useful for comparing results
go test -bench=. -count=5 ./fib> old.txt
go test -bench=. -count=5 ./fib |tee new.txt
benchstat old.txt new.txt
benchstat {old,new}.txt
    • how fast will this bench? I think it's super fast!
package popcnt

import "testing"

const m1 = 0x5555555555
const m2 = 0x33333
const m4 = 0x0f0f0f
const h01 = 0x0101010101 func popcnt(x uint64) uint64 {
x -= (x >> 1) & m1
x = (x & m2) + ((x >> 2) & m2)
x = (x + (x >> 4)) & m4
return (x * h01) >> 56
}
func benchmarkPopcnt(b *testing.B) {
for i := 0; i < b.N; i++ {
popcnt(uint64(i)) //optimied away
}
}
#go test -bench=. ./popcnt
    • 但是被优化没有效果,要改为如下才有bench的效果
#change it to this:
var result uint64
func benchmarkPopcnt(b *testing.B) {
var r uint64
for i:=0;i<b.N;i++ {
r = popcnt(uint64(i))
}
result=r
}
    • 自己测试还是没效果,不知道为什么
  • CPU profile
go test -run=XXX -bench=IndexByte -cpuprofile=/tmp/c.p bytes
go tool pprof bytes.test /tmp/c.p
#note: -run=XXX to disable test,you only need benchmark
  • godoc
cd godoc
golang.org/x/tools/cmd/godoc
vim main.go
add one line in main--defer profile.Start().Stop()
then exec in vim:GoImports
go install -v .
godoc -http=9000
open browser and open localhost:9000
go tool pprof $(which godoc) /var/...cpu.pprof
  • enable output of GCloggin
env GODEBUG=gctrace=1 godoc -http=:8080
  • import net/http/pprof package will register a handler at /debug/pprof and default http.serveMux

it will visible if you use http.listenSndServe(adress,nil)

godoc -http:=8080,show /debug/pprof
  • some slice and string translate...

五、晚场辩论

rust-lang.org

//GO
err := f(x)
if err != nil {
retrun err;
} //Rust
try!(f(x));
f(x)?

一个关于冗长与magic的讨论

六、原射手CEO

gomobile和动态库的使用

七、米嘉

github.com/mijia/gobuildweb

github.com/mijia/web-starter-kit

@fswatch $(GO_FILES) $(TEMPLATES) | xargs -n1 -l{} make restart ||make kill
  • chubby--at the heart of google
  • go Proverbs: simple,Poetic,Pithy,no magic,composing,interface,adaptor
  • request --> onion --> response
  • basiclly we put a lot of things inside handler: like  parse request,query db,user auth, CRUD model objects, biz logic, then render the result to response xml,json etc. or panic/error.

  • go web packages:

dozens of frameworks

julienschmidt/httprouter

codegangstar/negroni

www.gorillatoolkit.org

  • go generate according to database scheme

github.com/mijia/modelg

  • go benchmark

load_test.go//测试1000000LRUcache

package demo1

import (
"fmt"
"testing"
"time"
) //TestPutPerf load tests
func TestPutPerf(t *testing.T) {
fmt.Printf("load testing on 1M size cache\n")
size := 1000000
cache := newLRUCache(size)
start := time.Now()
for i,td := range testData {
if i%10000 == 0 {
end := time.Now()
fmt.Printf("Num: %d, Used time: %v\n", i, end.Sub(start))
start = end
}
cache.Put(td.url,td.body)
}
}
go test -c
./demo1.test -test.run=Perf
//lru_cache_test.go
package demo1
import (
"fmt"
"testing"
) type testDataType struct {
url string
body string
} var testData []testDataType const testDataSize = 10000100 func init () {
testData = make([]testDataType, testDataSize)
for i:= 0; i< testDataSize; i++ {
url := fmt.Sprintf("www.fake.com/%d",i)
testData[i] = testDataType {
url: url,
body: fmt.Sprintf("This is page <b>%s</b>!",url),
}
}
} func TestBasics(t *testing.T) {
cache := newLRUCache(2)
cache.Put("1","1")
cache.Put("2","2")
res, ok := cache.Get("1")
if !ok := || res != "1" {
t.Errorf("unexpected!")
}
cache.Put("4","4")
if _, ok := cache.Get("2");ok {
t.Errorf("unexpected")
}
} //go tool pprof
func BenchmarkCacheFull1KSize(b *test.B) {
benchmarkCacheFull(b,1000)
}
func BenchmarkCacheFull1MSize(b *testing.B) {
benchmarkCacheFull(b,1000000)
}
func benchmarkCacheFull(b *testing.B, size int) {
cache := newLRUCache(size)
for i :=0;i<size;i++ {
cache.Put(testData[i].url,testData[i].body)
}
//两个Put之间有noise必须先做profiling,
//go tool pprof demo1.test prof.out -->#web
f, _ := os.Create("prof.out")
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
//先填满,之后测试每push 一个item需要多长时间
b.ResetTimer()
for i :=0; i< b.N; i++ {
c:=(i+size) % testDataSize
cache.Put(testData[c].url, testData[c].body)
}
} //demo2
//go test -v . -run XXX -bench Mill
//./demo2.test -test.run XXX -test.bench Milli -test.cpuprofile=prof.out
//go tool pprof demo2.test prof.out --> web
./demo1.test -test.run=xxx -test.bench Full
#./demo1.test -test.run=xxx -test.bench Full -test.cpuprofile=prof.out 这是不准确的,因为有很多noise,用上面方法

八、Marcel van Lohuizen -- Google Go team

golang.org/x/text 实现

  • I18n and L10n 国际化与本地化

搜索排序,大小写,双向文本,注入翻译,数字货币,日期,单位转换

  • Go uses UTF-8
const beijing="北京市"
for index,runeValue :=range beijing {
fmt.Printf("%#U 从第%d字节开始\n",runeValue,index)
}
//北从0,京从3,市从6
  • 文本的序列本质
const flags="												

最新文章

  1. [转载]TFS源代码管理
  2. sqoop
  3. curl 发送get post请求
  4. MAC在Finder栏显示所浏览文件夹路径的方法
  5. 009Linux密码故障排除
  6. jd-gui 反编译后去除注释
  7. (转)Salesforce的440亿美金并购宣告企业软件市场进入3.0互联网化时代
  8. oracle error info
  9. 35个jQuery小技巧!
  10. c++中参数传递和函数返回简析
  11. The method queryForMap(String, Object...) from the type JdbcTemplate refers to the missing type DataAccessException
  12. Android开发技巧——实现底部图标文字的导航栏(已更新)
  13. .NET core2.0 发布至IIS中
  14. Mac OSX 系统搭建 Java 开发环境
  15. pta总结1
  16. 制作OTA升级包
  17. JavaScript原型详解
  18. Educational Codeforces Round 42 (Rated for Div. 2) D. Merge Equals
  19. 每日英语:Doc, Do I Need A Juice Cleanse?
  20. CGLIB介绍

热门文章

  1. CSS 分组
  2. UML精粹3 - 类图,序列图,CRC
  3. textview 显示html方法解析
  4. [ActionScript 3.0] AS3.0将图像的Alpha通道转换为黑白图像(复制通道方式)
  5. angularjs如何在视图渲染结束之后,或者render之后执行指令中的link方法呢?
  6. [计算机取证技术] VDI-in-a-Box Analysis Results
  7. 执行powershell脚本
  8. tsclient rdesktop remina freerdp
  9. js加载顺序
  10. imp导入oracle的dmp备份数据