beego postgresql最大数据库连接

时间:2014-11-27 12:55:43

标签: postgresql go beego

我正在尝试使用beego制作一个简单的api应用程序。在压力测试期间,出现了意想不到的问题。在~16,400之前,一切都以极快的速度执行。在16400查询几乎所有停止后,每秒运行1-2个请求。我觉得beego无法分配与数据库的连接。我试图更改maxIdle,maxConn参数但没有效果。

UPD 即可。与其他数据库相同的问题

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()
}

型号:

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()
}

到达~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)

达到~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)
即使在30秒后

相同的图片

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 个答案:

没有答案
相关问题