dongteng0748 2015-04-08 15:37
浏览 53

golang请求Orientdb http接口错误

I am playing wit golang and orientdb to test them. i have written a tiny web app which uppon a request fetches a single document from local orientdb instance and returns it. when i bench this app with apache bench, when concurrency is above 1 it get following error:

2015/04/08 19:24:07 http: panic serving [::1]:57346: Get http://localhost:2480/d ocument/t1/9:1441: EOF

when i bench Orientdb itself, it runs perfectley OK with any cuncurrency factor. also when i change the url to fetch from this document to anything (other program whritten in golang, some internet site etc) the app runs OK. here is the code:

func main() {
    fmt.Println("starting ....")

    var aa interface{}
    router := gin.New()
    router.GET("/", func(c *gin.Context) {
        ans := getdoc("http://localhost:2480/document/t1/9:1441")
        json.Unmarshal(ans, &aa)
        c.JSON(http.StatusOK, aa)
    })

    router.Run(":3000")
}
func getdoc(addr string) []byte {
    client := new(http.Client)
    req, err := http.NewRequest("GET", addr, nil)
    req.SetBasicAuth("admin","admin")
    resp, err := client.Do(req)
    if err != nil {
        fmt.Println("oops", resp, err)
        panic(err)
    }
    defer resp.Body.Close()
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }
    return body
}

thanks in advance

  • 写回答

1条回答 默认 最新

  • dongya9346 2015-04-08 16:25
    关注

    The keepalive connections are getting closed on you for some reason. You might be overwhelming the server, or going past the max number of connections the database can handle.

    Also, the current http.Transport connection pool doesn't work well with synthetic benchmarks that make connections as fast as possible, and can quickly exhaust available file descriptors or ports (issue/6785).

    To test this, I would set Request.Close = true to prevent the Transport from using the keepalive pool. If that works, one way to handle this with keepalive, is to specifically check for an io.EOF and retry that request, possibly with some backoff delay.

    评论

报告相同问题?

悬赏问题

  • ¥100 支付宝批量检测实名工具
  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题