dongtuliao6760 2014-11-27 12:55
浏览 166

beego postgresql最大数据库连接数

I'm trying to make a simple api application using beego. During the stress test, there was an unexpected problem. Before ~16400 requests everything executes at fantastic speed. After 16400 queries almost all stops, runs 1-2 requests per second. I have a feeling that beego can not allocate a connection to the database. I tried to change maxIdle, maxConn parameters but no effect.

UPD. the same problem with other databases

MainController:

package controllers

import (
    models "github.com/Hepri/taxi/models"
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/orm"
)

type MainController struct {
    beego.Controller
}

func (c *MainController) Get() {
    o := orm.NewOrm()
    app := models.ApiApp{}
    err := o.Read(&app)

    if err == orm.ErrMissPK {
        // do nothing
    }
    c.ServeJson()
}

Model:

package models

const (
    CompanyAccessTypeAll      = 1
    CompanyAccessTypeSpecific = 2
)

type ApiApp struct {
    Id                int    `orm:"auto"`
    Token             string `orm:"size(100)"`
}

func (a *ApiApp) TableName() string {
    return "api_apps"
}

main.go:

package main

import (
    models "github.com/Hepri/taxi/models"
    _ "github.com/Hepri/taxi/routers"
    "github.com/astaxie/beego"
    "github.com/astaxie/beego/orm"
    _ "github.com/lib/pq"
)

func main() {
    orm.RegisterDriver("postgres", orm.DR_Postgres)
    orm.RegisterDataBase("default", "postgres", "user=test password=123456 dbname=test sslmode=disable")
    orm.RegisterModel(new(models.ApiApp))
    beego.EnableAdmin = true
    orm.RunCommand()
    beego.Run()
}

before reach ~16400:

Benchmarking localhost (be patient)
^C

Server Software:        beegoServer:1.4.2
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        4 bytes

Concurrency Level:      10
Time taken for tests:   3.844 seconds
Complete requests:      16396
Failed requests:        0
Write errors:           0
Total transferred:      2492192 bytes
HTML transferred:       65584 bytes
Requests per second:    4264.91 [#/sec] (mean)
Time per request:       2.345 [ms] (mean)
Time per request:       0.234 [ms] (mean, across all concurrent requests)
Transfer rate:          633.07 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   2.2      0     275
Processing:     0    2  10.9      1     370
Waiting:        0    1   8.6      1     370
Total:          0    2  11.1      2     370

Percentage of the requests served within a certain time (ms)
  50%      2
  66%      2
  75%      2
  80%      2
  90%      2
  95%      3
  98%      3
  99%      4
 100%    370 (longest request)

after reach ~16400:

Benchmarking localhost (be patient)
^C

Server Software:        beegoServer:1.4.2
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        4 bytes

Concurrency Level:      10
Time taken for tests:   15.534 seconds
Complete requests:      16392
Failed requests:        0
Write errors:           0
Total transferred:      2491584 bytes
HTML transferred:       65568 bytes
Requests per second:    1055.22 [#/sec] (mean)
Time per request:       9.477 [ms] (mean)
Time per request:       0.948 [ms] (mean, across all concurrent requests)
Transfer rate:          156.63 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.3      0      11
Processing:     0    2  16.7      1     614
Waiting:        0    1  15.7      1     614
Total:          0    2  16.7      1     614

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      2
  80%      2
  90%      2
  95%      2
  98%      3
  99%      3
 100%    614 (longest request)

same picture even after 30 seconds

Benchmarking localhost (be patient)
^C

Server Software:        beegoServer:1.4.2
Server Hostname:        localhost
Server Port:            8080

Document Path:          /
Document Length:        4 bytes

Concurrency Level:      10
Time taken for tests:   25.585 seconds
Complete requests:      16391
Failed requests:        0
Write errors:           0
Total transferred:      2491432 bytes
HTML transferred:       65564 bytes
Requests per second:    640.65 [#/sec] (mean)
Time per request:       15.609 [ms] (mean)
Time per request:       1.561 [ms] (mean, across all concurrent requests)
Transfer rate:          95.10 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    1  10.1      0     617
Processing:     0    2  16.2      1     598
Waiting:        0    1  11.1      1     597
Total:          0    2  19.1      1     618

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      2
  75%      2
  80%      2
  90%      2
  95%      2
  98%      3
  99%      3
 100%    618 (longest request)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集
    • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
    • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
    • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)