小编Ter*_*rry的帖子

Golang程序内存泄漏?

我的golang程序(url监视器)有内存泄漏,它最终被内核(oom)杀死.环境:

$ go version
go version go1.0.3

$ go env
GOARCH="amd64"
GOBIN=""
GOCHAR="6"
GOEXE=""
GOGCCFLAGS="-g -O2 -fPIC -m64 -pthread"
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/data/apps/go"
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
CGO_ENABLED="1"
Run Code Online (Sandbox Code Playgroud)

码:

package main

import (
    "bytes"
    "database/sql"
    "flag"
    "fmt"
    _ "github.com/Go-SQL-Driver/MySQL"
    "ijinshan.com/cfg"
    "log"
    "net"
    "net/http"
    "net/smtp"
    "os"
    "strconv"
    "strings"
    "sync"
    "time"
)

var (
    Log           *log.Logger
    Conf          cfg.KVConfig
    Debug         bool
    CpuCore       int
    HttpTransport = &http.Transport{
        Dial: func(netw, addr string) (net.Conn, error) {
            deadline := time.Now().Add(30 * time.Second)
            c, err := net.DialTimeout(netw, addr, 20*time.Second)
            if …
Run Code Online (Sandbox Code Playgroud)

memory-leaks go

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

OPROFILE无法获得性能数据

我正在使用OPROFILE来收集一些性能数据.但我陷入困境.

这是我的shell:

~ # rm -f /root/.oprofile/daemonrc
~ # opcontrol --setup --no-vmlinux
~ # opcontrol --init
~ # opcontrol --reset
~ # opcontrol --start
~ # opcontrol --status

Daemon running: pid 14909    
Separate options: none
vmlinux file: none    
Image filter: none    
Call-graph depth: 0

~ # opcontrol --shutdown

Stopping profiling.
Killing daemon.

~ # opreport

error: no sample files found: profile specification too strict?

~ # tree /var/lib/oprofile/

/var/lib/oprofile/
??? abi
??? complete_dump
??? jitdump
??? opd_pipe
??? samples
    ??? …
Run Code Online (Sandbox Code Playgroud)

c performance oprofile

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

URL监视器在netstat中生成多个ESTABLISHED(连接)条目

我在Go中编写了一个URL监控程序,但经过一段时间后,我发现了很多ESTABLISHED条目netstat -nao|grep 80.

getHttpStatusCode函数:

    HttpClient = &http.Client{
        Transport: &http.Transport{
            Dial: func(netw, addr string) (net.Conn, error) {
                deadline := time.Now().Add(30 * time.Second)
                c, err := net.DialTimeout(netw, addr, 20*time.Second)
                if err != nil {
                    return nil, err
                }

                c.SetDeadline(deadline)
                c.SetReadDeadline(deadline)
                c.SetWriteDeadline(deadline)
                return c, nil
            },
        },
    }

// ...

func getHttpStatusCode(url string) int {
    if url == "" {
        return 200
    }

    req, err := http.NewRequest("GET", url, nil)
    if err != nil {
        return 0
    }

    req.Close = true
    req.Header.Add("User-Agent", …
Run Code Online (Sandbox Code Playgroud)

http go

4
推荐指数
1
解决办法
617
查看次数

标签 统计

go ×2

c ×1

http ×1

memory-leaks ×1

oprofile ×1

performance ×1