golang--gopher北京大会(2)(rework)
三、七牛老许
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="golang--gopher北京大会(2)(rework)的更多相关文章
- golang--gopher北京大会(1)
大会感想:牛人真的很能写代码,实现很多功能,而且开源的精品越多,影响力越大,越能过上dream life.比如beego的作者,去了America,进入了Apple.另外,精英们特点是表达能力很强,也 ...
- 阿里聚安全受邀参加SFDC安全大会,分享互联网业务面临问题和安全创新实践
现今,技术引领的商业变革已无缝渗透入我们的日常生活,「技术改变生活」的开发者们被推向了创新浪潮的顶端.国内知名的开发者技术社区 SegmentFault 至今已有四年多了,自技术问答开始,他们已经发展 ...
- [Go] 理解 golang 中的 nil
nil是什么 相信写过Golang的程序员对下面一段代码是非常非常熟悉的了: if err != nil { // do something.... } 当出现不等于nil的时候,说明出现某些错误了, ...
- Go语言的9大优势和3大缺点, GO语言最初的定位就是互联网时代的C语言, 我为什么放弃Go语言
Go语言的9大优势和3大缺点 转用一门新语言通常是一项大决策,尤其是当你的团队成员中只有一个使用过它时.今年 Stream 团队的主要编程语言从 Python 转向了 Go.本文解释了其背后的九大原因 ...
- Go语言的前景分析
本文为原创文章,转载注明出处,asdfasdfasdf 欢迎扫码关注公众号flysnow_org或者网站http://www.flysnow.org/,第一时间看后续精彩文章.觉得好的话,顺手分享到朋 ...
- WeX5与阿里内测的Weex与有何纠葛?快来看HTML5开发圈那些逗逼事儿!
4月21日~23日,由infoQ主办的2016 Qcon大会北京站如期举行. HTML5开发已经成为移动开发/前端专题中无可争议的焦点,核心议题已经由前几年的是否该用HTML5转向了如何高性能.高效率 ...
- 2017年IT互联网圈跑会指南~
啦啦啦~要放假啦,还有十多天就要过年啦,要走亲访友啦!相信大家也是各种胡吃海喝后,啊咧~腰上好像多了好几圈o(>﹏<)o为了让小伙伴们及时制定年后行程(减膘)计划,活动家特此奉上2017年 ...
- gmic全球移动互联网大会 全球九站已开启!
由长城会主办的全球移动互联网大会( 简称GMIC)已成长为世界范围内最具影响力的辐射并连结东西半球的移动互联网商务平台,是最大规模的移动互联网行业盛会. 2017gmic全球移动互联网大会北京站将于2 ...
- 全球移动互联网大会gmic 2017为什么值得参加?
长城会CEO郝义认为,"科学产业化将会推动科学复兴,"而本次GMIC 北京 2017也将首次引入了高规格科学家闭门峰会,专门设置G-Summit全球科学创新峰会,以"科学 ...
随机推荐
- trace工具,c++/c#/python
下载地址: http://files.cnblogs.com/files/wjx0912/xtrace.rar 很方便的调试工具,已在c#, vc2015, python2.7.10环境下测试. 闭 ...
- kafka2.9.2的伪分布式集群安装和demo(java api)测试
目录: 一.什么是kafka? 二.kafka的官方网站在哪里? 三.在哪里下载?需要哪些组件的支持? 四.如何安装? 五.FAQ 六.扩展阅读 一.什么是kafka? kafka是LinkedI ...
- [2014.01.27]WFsoft.wfWebCtrl.wfUrlPager 3.2
wfUrlPager多功能.Net翻页组件,使用简单,功能强大. 提供"首页","上一页","下一页","末页",&qu ...
- mybatis中当实体类的字段名和表结构中的字段名不一致的时候的处理
1.在sql语句中使用列的别名 比如:select order_id id,orderNo orderno ,order_price price from order where order_id = ...
- less笔记
koala工具 注释: 1./**/,可以被编译 2.//,不可以被编译 申明变量: @box_width:300px; .box{ width:@box_wid ...
- 5.Integer to Roman && Roman to Integer
Roman chart: http://literacy.kent.edu/Minigrants/Cinci/romanchart.htm Integer to Roman Given an inte ...
- 12. Linux在线升级yum
软件包仓库源 将yum源放在/etc/yum.repo.d root@cfm880 Packages]# cd /etc/yum.repos.d/[root@cfm880 yum.repos.d]# ...
- ios8 滚动事件解放了
http://developer.telerik.com/featured/scroll-event-change-ios-8-big-deal/ 这是外国人写的一篇文章,我这里直接贴了一个链接,敢兴 ...
- Thinkphp源码分析系列(二)–引导类
在上一章我们说到,ThinkPHP.php在设置完框架所需要的变量和调教好环境后,在最后调用了 Think\Think::start(); 即Think命名空间中的Think类的静态方法start ...
- PHP递归实现层级树状展现数据
树状数据展现很常用,今天学习了PHP的递归,也来总结总结! PHP代码: function _getTreeList_custom1($data,$parent_id,$depth) { $retur ...