小编Vis*_*mar的帖子

当golang为字符串到字节转换进行分配时

var testString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
//var testString = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
func BenchmarkHashing900000000(b *testing.B){
    var bufByte = bytes.Buffer{}
    for i := 0; i < b.N ; i++{
        bufByte.WriteString(testString)
        Sum32(bufByte.Bytes())
        bufByte.Reset()
    }
}

func BenchmarkHashingWithNew900000000(b *testing.B){
    for i := 0; i < b.N ; i++{
        bytStr := []byte(testString)
        Sum32(bytStr)
    }
}
Run Code Online (Sandbox Code Playgroud)

测试结果:

With  testString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
BenchmarkHashing900000000-4         50000000            35.2 ns/op         0 B/op          0 allocs/op
BenchmarkHashingWithNew900000000-4  50000000            30.9 ns/op         0 B/op          0 allocs/op

With testString = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ"
BenchmarkHashing900000000-4         30000000            46.6 ns/op         0 B/op          0 allocs/op …
Run Code Online (Sandbox Code Playgroud)

allocation go

6
推荐指数
1
解决办法
1682
查看次数

Goroutine 长时间处于 IO 等待状态

我有一个大流量服务器(超过 800K qps),使用 go1.7。

http://urltoserver:debugport/debug/pprof/goroutine?debug=2我看到8K个goroutines,其中近1800个正在IO等待几分钟。其中一个 Goroutine 堆栈如下所示。

    goroutine 128328653 [IO wait, 54 minutes]:
    net.runtime_pollWait(0x7f0fcc60c378, 0x72, 0x7cb)
      /usr/local/go/src/runtime/netpoll.go:160 +0x59
    net.(*pollDesc).wait(0xc4231d0a00, 0x72, 0xc42479fa20, 0xc42000c048)
      /usr/local/go/src/net/fd_poll_runtime.go:73 +0x38
    net.(*pollDesc).waitRead(0xc4231d0a00, 0x92f200, 0xc42000c048)
      /usr/local/go/src/net/fd_poll_runtime.go:78 +0x34
    net.(*netFD).Read(0xc4231d09a0, 0xc423109000, 0x1000, 0x1000, 0x0, 0x92f200, 0xc42000c048)
      /usr/local/go/src/net/fd_unix.go:243 +0x1a1
    net.(*conn).Read(0xc4234282b8, 0xc423109000, 0x1000, 0x1000, 0x0, 0x0, 0x0)
      /usr/local/go/src/net/net.go:173 +0x70
    net/http.(*connReader).Read(0xc420449840, 0xc423109000, 0x1000, 0x1000, 0xc422b38b68, 0x100000000, 0xc421810601)
      /usr/local/go/src/net/http/server.go:586 +0x144
    bufio.(*Reader).fill(0xc422e22360)
      /usr/local/go/src/bufio/bufio.go:97 +0x10c
    bufio.(*Reader).Peek(0xc422e22360, 0x4, 0x7a066c, 0x4, 0x1, 0x0, 0x0)
      /usr/local/go/src/bufio/bufio.go:129 +0x62
    net/http.(*conn).readRequest(0xc422b38b00, 0x931fc0, 0xc424d19440, 0x0, 0x0, 0x0)
      /usr/local/go/src/net/http/server.go:762 +0xdff
    net/http.(*conn).serve(0xc422b38b00, 0x931fc0, …
Run Code Online (Sandbox Code Playgroud)

linux go httpserver

5
推荐指数
1
解决办法
1万
查看次数

std :: bind无法按预期工作

std::vector<int> v1;
std::function<void(const int&)> funct = 
static_cast<std::function<void(const int&)>>(std::bind(
                                            &std::vector<int>::push_back,
                                            &v1,
                                            std::placeholders::_1));
Run Code Online (Sandbox Code Playgroud)

这给了我no matching function for call to bind.

我能做到这一点:

threadPool.push_back(std::thread(runThread<lazyFunct>,
                     std::bind(&LazySkipList<int>::add,
                     &lsl, std::placeholders::_1), 0, 1000000, 1000000));
Run Code Online (Sandbox Code Playgroud)

我正在使用Xcode 4.4和llvm C++ 11支持.

c++ c++11

3
推荐指数
1
解决办法
1561
查看次数

标签 统计

go ×2

allocation ×1

c++ ×1

c++11 ×1

httpserver ×1

linux ×1