swoft-cloud / swoft

🚀 PHP Microservice Full Coroutine Framework
https://swoft.org
Apache License 2.0
5.58k stars 786 forks source link

压力过大连接池不足时抛出异常 #241

Closed linkdrone closed 6 years ago

linkdrone commented 6 years ago
Q A
Bug report? yes/no
Feature request? yes/no
Swoft version 1.0.0
Swoole version >=2.1.2
PHP version 7.1.14
Runtime environment Mac/CentOS 7

Details

Swoft连接池在连接不够用时报错(是否进行等待更加合理)

出错代码

Notice: Undefined variable: result in /Users/wanqing/Develop/demo-swoft/vendor/swoft/framework/src/Pool/ConnectionPool.php on line 252
PHP Notice:  Undefined variable: result in /Users/wanqing/Develop/demo-swoft/vendor/swoft/framework/src/Pool/ConnectionPool.php on line 252

配置

# Database Master nodes
DB_NAME=dbMaster
DB_URI=127.0.0.1:3306/test?user=root&password=&charset=utf8,127.0.0.1:3306/test?user=root&password=&charset=utf8
DB_MIN_ACTIVE=5
DB_MAX_ACTIVE=10
DB_MAX_WAIT=20
DB_MAX_WAIT_TIME=3
DB_MAX_IDLE_TIME=60
DB_TIMEOUT=2

# Database Slave nodes
DB_SLAVE_NAME=dbSlave
DB_SLAVE_URI=127.0.0.1:3306/test?user=root&password=&charset=utf8,127.0.0.1:3306/test?user=root&password=&charset=utf8
DB_SLAVE_MIN_ACTIVE=5
DB_SLAVE_MAX_ACTIVE=10
DB_SLAVE_MAX_WAIT=20
DB_SLAVE_MAX_WAIT_TIME=3
DB_SLAVE_MAX_IDLE_TIME=60
DB_SLAVE_TIMEOUT=3

Entity

<?php
namespace App\Models\Entity;

use Swoft\Db\Model;
use Swoft\Db\Bean\Annotation\Column;
use Swoft\Db\Bean\Annotation\Entity;
use Swoft\Db\Bean\Annotation\Id;
use Swoft\Db\Bean\Annotation\Required;
use Swoft\Db\Bean\Annotation\Table;
use Swoft\Db\Types;

/**
 * @Entity()
 * @Table(name="sys_test")
 * @uses      SysTest
 */
class SysTest extends Model
{
    /**
     * @var int $id 
     * @Id()
     * @Column(name="id", type="integer")
     */
    private $id;

    /**
     * @var string $name 
     * @Column(name="name", type="string", length=11)
     */
    private $name;

    /**
     * @param int $value
     * @return $this
     */
    public function setId(int $value)
    {
        $this->id = $value;

        return $this;
    }

    /**
     * @param string $value
     * @return $this
     */
    public function setName(string $value): self
    {
        $this->name = $value;

        return $this;
    }

    /**
     * @return mixed
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * @return string
     */
    public function getName()
    {
        return $this->name;
    }

}

Controller

/**
 * action demo
 *
 * @Controller(prefix="/route")
 */
class RouteController
{
    /**
     * @RequestMapping()
     */
    public function index()
    {
        $id = rand(0, 43042);
        $info = SysTest::findById($id)->getResult();
//        var_dump($info);
        return $info;
    }
}

压测工具及截图

JMeter

image

stelin commented 6 years ago

此问题是Mac下复现的,等待swoole解决!