Giter Site home page Giter Site logo

louislivi / smproxy Goto Github PK

View Code? Open in Web Editor NEW
1.8K 1.8K 255.0 504 KB

Swoole MySQL Proxy 一个基于 MySQL 协议,Swoole 开发的MySQL数据库连接池。 A MySQL database connection pool based on MySQL protocol and Swoole.

Home Page: https://smproxy.louislivi.com

License: MIT License

PHP 99.38% Shell 0.05% Dockerfile 0.58%
composer connection-pool connections coroutines mycat mysql php pool proxy smproxy swoole swoole-mysql-proxy

smproxy's Introduction

中文 | English

  /$$$$$$  /$$      /$$ /$$$$$$$
 /$$__  $$| $$$    /$$$| $$__  $$
| $$  \__/| $$$$  /$$$$| $$  \ $$ /$$$$$$   /$$$$$$  /$$   /$$ /$$   /$$
|  $$$$$$ | $$ $$/$$ $$| $$$$$$$//$$__  $$ /$$__  $$|  $$ /$$/| $$  | $$
 \____  $$| $$  $$$| $$| $$____/| $$  \__/| $$  \ $$ \  $$$$/ | $$  | $$
 /$$  \ $$| $$\  $ | $$| $$     | $$      | $$  | $$  >$$  $$ | $$  | $$
|  $$$$$$/| $$ \/  | $$| $$     | $$      |  $$$$$$/ /$$/\  $$|  $$$$$$$
 \______/ |__/     |__/|__/     |__/       \______/ |__/  \__/ \____  $$
                                                               /$$  | $$
                                                              |  $$$$$$/
                                                               \______/

release forks stars Build Status Gitter license SMProxy Backers on Open Collective Sponsors on Open Collective

Swoole MySQL Proxy

一个基于 MySQL 协议,Swoole 开发的MySQL数据库连接池。

原理

将数据库连接作为对象存储在内存中,当用户需要访问数据库时,首次会建立连接,后面并非建立一个新的连接,而是从连接池中取出一个已建立的空闲连接对象。 使用完毕后,用户也并非将连接关闭,而是将连接放回连接池中,以供下一个请求访问使用。而连接的建立、断开都由连接池自身来管理。

同时,还可以通过设置连接池的参数来控制连接池中的初始连接数、连接的上下限数以及每个连接的最大使用次数、最大空闲时间等等。 也可以通过其自身的管理机制来监视数据库连接的数量、使用情况等。超出最大连接数会采用协程挂起,等到有连接关闭再恢复协程继续操作。

特性

  • 支持读写分离
  • 支持数据库连接池,能够有效解决 PHP 带来的数据库连接瓶颈
  • 支持 SQL92 标准
  • 采用协程调度
  • 支持多个数据库连接,多个数据库,多个用户,灵活搭配
  • 遵守 MySQL 原生协议,跨语言,跨平台的通用中间件代理
  • 支持 MySQL 事务
  • 支持 HandshakeV10 协议版本
  • 完美兼容 MySQL5.5 - 8.0
  • 兼容各大框架,无缝提升性能

设计初衷

PHP 没有连接池,所以高并发时数据库会出现连接打满的情况,Mycat 等数据库中间件会出现部分 SQL 无法使用,例如不支持批量添加等,而且过于臃肿。 所以就自己编写了这个仅支持连接池和读写分离的轻量级中间件,使用 Swoole 协程调度 HandshakeV10 协议转发使程序更加稳定,不用像 Mycat 一样解析所有 SQL 包体,增加复杂度。

开发与讨论

贡献者列表

因为有你们,SMProxy 才能走到现在。

Backers

Thank you to all our backers! 🙏 [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

smproxy's People

Contributors

dingzihu avatar fghrsh avatar louislivi avatar monkeywithacupcake avatar no-serve-people avatar txznothing avatar wi1dcard avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

smproxy's Issues

使用mysql进行连接,选择数据库存在类似缓存的问题

Describe Your Environment (描述你的环境)

  • System: contos6.5
  • PHP version: 5.3.29
  • Swoole version: 4.0
  • SMProxy version: 1.2.7

How to Reproduce the Problem? (如何重现问题)

  1. 直接按照配置连接
  2. mysql_pconnect($host,$user,$passwd)连接数据库后直接使用 mysql_select_db 选择数据库
  3. 执行sql显示未选择数据库3D000No database selected

Expected Behavior (预期行为)

...直接显示查询结果

Actual Behavior (实际行为)

...3D000No database selected 报错

More Information (更多信息)

... 使用mysql_pconnect查询所有的数据库,然后循环显示数据库后,查询恢复正常

配置多个数据库时,使用navicat链接会报database not selected

Describe Your Environment (描述你的环境)

  • System: Ubuntu16.04
  • PHP version: 7.3
  • Swoole version: 4.3.5
  • SMProxy version: 1.2.8

How to Reproduce the Problem? (如何重现问题)

配置多个数据库时,使用navicat12链接代码,执行命令会报database not selected

Expected Behavior (预期行为)

能正确选择数据库执行相应命令
...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

连接池连接泄露

Describe Your Environment (描述你的环境)

  • System: mac os
  • PHP version: 7.1
  • Swoole version: 4.2.12
  • SMProxy version: v1.2.7@c3ea536

How to Reproduce the Problem? (如何重现问题)

  1. 配置 startConns:0,maxSpareConns:1,maxConns:3,swoole 的 worker_num:1,其它都默认,这样便于查看测试的问题
  2. 启动服务器,开启1个mysql客户端(用mysql命令的客户端)这时看到mysql的show processlist 有1个SMProxy的连接,在客户端里use test; 并执行一个查询表现正常;
  3. 不要关闭mysql客户端重启 SMProxy,然后在 mysql 里执一个上一次的 select,服务器出错,数据无法返回,尝试 use test 偶尔会提示成功,在mysql服务器的 show processlist后看到n多空闲连接,越来越多

Expected Behavior (预期行为)

应该可以重连

Actual Behavior (实际行为)

一直失败,而且导致服务器连接泄露,过一会可以重连,但是在mysql里的连接不自动断开,一直sleep状态

More Information (更多信息)

求助,遇到链接错误

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: php7.2
  • Swoole version: 4.2.10-beta
  • SMProxy version: latest

How to Reproduce the Problem? (如何重现问题)

  1. 启动程序,客户端连接不了,服务端报错

日志

[2018-12-17 23:08:40 *32060.4] ERROR sw_coro_check_bind (ERROR 10002): client has already been bound to another coroutine#43, reading or writing of the same socket in multiple coroutines at the same time is not allowed.
Stack trace:
#0 Swoole\Coroutine\Client->send() called at [phar:///home/src/smproxy/SMProxy/src/SMProxyServer.php:87]
#1 SMProxy\SMProxyServer->SMProxy{closure}() called at [phar:///home/src/smproxy/SMProxy/src/Base.php:32]

bin/server -c 不携带路径会报 NOTICE

➜  smproxy bin/server -c

PHP Notice:  Undefined offset: 2 in /Users/xxx/web/smproxy/src/Command/Command.php on line 29
PHP Stack trace:
PHP   1. {main}() /Users/xxx/web/smproxy/bin/server:0
PHP   2. SMProxy\Command\Command->run() /Users/xxx/web/smproxy/bin/server:10

Notice: Undefined offset: 2 in /Users/xxx/web/smproxy/src/Command/Command.php on line 29

Call Stack:
    0.0024     391384   1. {main}() /Users/xxx/web/smproxy/bin/server:0
    0.0471    1897160   2. SMProxy\Command\Command->run() /Users/xxx/web/smproxy/bin/server:10

ERROR: No such file or directory!

观察 /Users/xxx/web/smproxy/src/Command/Command.php on line 29 代码发现,应当做好判断。

再次发现几个问题

  1. 版本号是否应当采用语义化版本?
  2. Git 应当忽略 vendor 文件夹。
  3. 有一张图片无法加载。
    image
  4. Travis 脚本应当使用 composer install 而非 composer update
  5. composer.json 配置内的类型应当为 project,参考:https://docs.phpcomposer.com/04-schema.html#type
  6. 建议增加 php-cs-fixer 统一代码风格。

Swoole Coroutine Mysql可以与SMProxy 结合提升效率吗

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.2
  • Mysql version: 5.6
  • Swoole version: 4.4.5
  • SMProxy version:1.2.9

How to Reproduce the Problem? (如何重现问题)

我在这之前用的是swoole的协程版本的mysql,然后再将数据库连接改为smproxy server配置的信息,执行效率却比之前降低了,原来0.06s就可以执行100条请求写入,现在需要0.09s,1000条并发100原来要1.4s现在要1.6s,是我哪里配置不对吗,现在只是本地一个数据库,简单的测试一下,感觉效果不明显,并发高的情况下两者差不多.

docker 下一直无法运行,求助

smproxy_1 | SMProxy version: v1.2.3
smproxy_1 |
smproxy_1 | Server starting ...
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)
smproxy_1 | ERROR: The server have been running! (PID: 11)

尽可能减少 Force Push

修改提交记录 Force Push 之后我这边很容易把改过的提交记录又推上去,尽可能减少 Force Push 为好。

image

连接失败:Too many connectionss

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.2.5
  • Swoole version: 4.2.12
  • SMProxy version: v1.2.7@938430e

How to Reproduce the Problem? (如何重现问题)

  1. 开启服务bin/SMProxy start
  2. 在控制台中执行 php db.php

Expected Behavior (预期行为)

打印出结果

Array
(
    [id] => 22
    [title] => 这是一个测试的写入1111
    [content] => 这是一个测试的写入cont1111
    [created] => 1417686531
    [status] => 1
)
0.014184951782227

Actual Behavior (实际行为)

第一次开启服务,会在控制台中打印出数组,但是再运行bin/SMProxy status

会显示

The server is not running

第二次再开启服务,就会出现如下错误!

PHP Warning:  mysqli::__construct(): (08004/1040): Too many connections in 1.php on line 3

Warning: mysqli::__construct(): (08004/1040): Too many connections in 1.php on line 3
连接失败:Too many connectionss

More Information (更多信息)

db.php

$start = microtime(true);
$conn = new \mysqli('localhost', 'root', '123456', 'man_db_read', 3306);
if($conn->connect_error){
    die('连接失败:'.$conn->connect_error);
}
$sql = "SELECT * FROM man_articles LIMIT 1";
$result = $conn->query($sql);
if($result->num_rows > 0){
    while($row = $result->fetch_assoc()){
        print_r($row);
    }
}else{
    echo 'no record!';
}
$conn->close();
print_r(microtime(true) - $start);
exit;

不知道是不是我的配置有问题!

database.json

{
  "database": {
    "account": {
      "root": {
        "user": "root",
        "password": "123456"
      }
    },
    "serverInfo": {
      "server1": {
        "write": {
          "host": ["127.0.0.1"],
          "port": 3306,
          "timeout": 0.5,
          "account": "root"
        },
        "read": {
          "host": ["127.0.0.1"],
          "port": 3306,
          "timeout": 0.5,
          "account": "root"
        }
      }
    },
    "databases": {
      "man_db_read": {
        "serverInfo": "server1",
        "startConns": "swoole_cpu_num()*10",
        "maxSpareConns": "swoole_cpu_num()*10",
        "maxSpareExp": 3600,
        "maxConns": "swoole_cpu_num()*20",
        "charset": "utf8mb4"
      },
      "man_db_write": {
        "serverInfo": "server1",
        "startConns": "swoole_cpu_num()*10",
        "maxSpareConns": "swoole_cpu_num()*10",
        "maxSpareExp": 3600,
        "maxConns": "swoole_cpu_num()*20",
        "charset": "utf8mb4"
      }
    }
  }
}

server.json

  "server": {
    "user": "root",
    "password": "123456",
    "charset": "utf8mb4",
    "host": "0.0.0.0",
    "port": "3366",
    "mode": "SWOOLE_PROCESS",
    "sock_type": "SWOOLE_SOCK_TCP",
    "logs": {
      "open":true,
      "config": {
        "system": {
          "log_path": "ROOT/logs",
          "log_file": "system.log",
          "format": "Y/m/d"
        },
        "mysql": {
          "log_path": "ROOT/logs",
          "log_file": "mysql.log",
          "format": "Y/m/d"
        }
      }
    },
    "swoole": {
      "worker_num": "swoole_cpu_num()",
      "max_coro_num": 6000,
      "open_tcp_nodelay": true,
      "daemonize": true,
      "heartbeat_check_interval": 60,
      "heartbeat_idle_time": 600,
      "reload_async": true,
      "log_file": "ROOT/logs/swoole.log",
      "pid_file": "ROOT/logs/pid/server.pid"
    },
    "swoole_client_setting": {
      "package_max_length": 16777215
    },
    "swoole_client_sock_setting": {
      "sock_type": "SWOOLE_SOCK_TCP"
    }
  }
}

连接池启动后自动退出

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.1.24
  • Swoole version: 4.2.11
  • SMProxy version: v1.2.6

How to Reproduce the Problem? (如何重现问题)

  1. 执行 start后查看status正常,但是运行后几秒时间报错

Expected Behavior (预期行为)

1.mysql.log
2019-01-12 11:20:13 [warning] oo many connections (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/SMProxyServer.php:257)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2019-01-12 11:20:19 [warning] SMProxy@Connection 127.0.0.1:3306 waiting timeout, timeout=0.5 (/Volumes/Ext/MacOsx/Codes/PhpstormProjects/SMProxy/src/MysqlPool/MySQLPool.php:222)
2.swoole.log
[2019-01-12 18:20:13 #97133.8] NOTICE Server is shutdown now.
[2019-01-12 18:20:43 *97145.1] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:43 *97149.5] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:43 *97151.7] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:43 *97146.2] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:44 *97148.4] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:44 *97150.6] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:44 *97144.0] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.
[2019-01-12 18:20:44 *97147.3] WARNING swWorker_onTimeout (ERROR 9011): worker exit timeout, forced to terminate.

More Information (更多信息)

...

原生与SMProxy 使用mysqli对比性能

Describe Your Environment (描述你的环境)

  • System: centos7
  • PHP version: 7.2
  • Mysql version: 5.5
  • Swoole version: 4.4
  • SMProxy version: 1.2.9

How to Reproduce the Problem? (如何重现问题)

1. 原生mysqli访问

<?php

    //使用面向对象进行数据库的连接,在创建对象的时候就自动的连接数据

    $mySQLi = new MySQLi('localhost','root','123456','app',3306);

    

    //判断数据库是否连接

    if($mySQLi -> connect_errno){

        die('连接错误' . $mySQLi -> connect_error);

    }
     
    //选择数据库
    /* change db to world db */
    //$mySQLi->select_db("app");

    //设置字符集

    $mySQLi -> set_charset('utf8');

    //编写sql语句并执行

    $sql = "select * from admin";

 

    //发送sql语句并执行,如果是select语句,返回的是一个对象,其他的返回来一个boolean.

    $res = $mySQLi -> query($sql);


    //使用$res对象里面的fetch_assoc()取出里面的数据.

    while($row = $res->fetch_assoc()){

     var_dump($row);

    }

    $res -> free();

    $mySQLi -> close();
  1. SMProxy访问
<?php

    //使用面向对象进行数据库的连接,在创建对象的时候就自动的连接数据

    $mySQLi = new MySQLi('127.0.0.1','root','123456','app', 3366);


    //判断数据库是否连接

    if($mySQLi -> connect_errno){

        die('连接错误' . $mySQLi -> connect_error);

    }
     
    //选择数据库
    /* change db to world db */
    //$mySQLi->select_db("app");

    //设置字符集

    $mySQLi -> set_charset('utf8');

    //编写sql语句并执行

    $sql = "select * from admin";

 

    //发送sql语句并执行,如果是select语句,返回的是一个对象,其他的返回来一个boolean.

    $res = $mySQLi -> query($sql);


    //使用$res对象里面的fetch_assoc()取出里面的数据.

    while($row = $res->fetch_assoc()){

     var_dump($row);

    }

    $res -> free();

    $mySQLi -> close();

原生访问数据库
ab -c 100 -n 1000 http://192.168.1.169:81/test/ab/mysqli_5.6.php
耗时:5s
使用连接池
ab -c 100 -n 1000 http://192.168.1.169:81/test/ab/mysqli_pool_5.6.php
耗时:6s

Expected Behavior (预期行为)

不是应该用连接池更快的吗,配置大都是系统默认的maxConns是cpu*20
查看运行状态
/me/smproxy/SMProxy status
SMProxy[v1.2.9] - Linux localhost.localdomain 3.10.0-957.5.1.el7.x86_64 #1 SMP Fri Feb 1 14:54:57 UTC 2019 x86_64
Host: 0.0.0.0, Port: 3366, PHPVerison: 7.2.6
SwooleVersion: 4.4.5, WorkerNum: 10
Process : 40 total, 4 query, 36 sleep

作者有空能不能看一下啊 这个就是想试一下能够提升多少性能的

有几点建议

1.client采用\Co\Client,根据消息swoole下个大版本计划移除异步API。
2.兼容docker,出个官方的docker镜像,可以采用docker的multi-stage build。基于容器的部署,可以直接sidecar进mysql容器。
3.连接数配置那里,生成dbconfig的时候,应该除以worker_num,这样配置的连接数才是实际数据库连接数。否则用户需要自己计算实际连接数,防止超出数据库配置。
4.worker_num配置建议支持function,例如一般连接数会设置为swoole_cpu_num(),或者swoole_cpu_num()*N这样。
5.增加一个配置,在服务启动的时候可以选择自动连接满maxSpareConns或者设定值或者不自动连接。默认自动满maxSpareConns。
6.日志组件可以兼容seaslog,SCG团队正在开发一整套日志收集,存储,分析系统,与seaslog完美结合。

releases中没有1.8的版本

我在Centos7上使用
php7.2
swoole4.3.2 发现cpu占用率在10%,查看文档说升级到1.8的版本,目前看到单PHAR只有1.7的版本

ERROR: SMProxy shutting down failed!

Describe Your Environment (描述你的环境)

  • System: Ubuntu18.04
  • PHP version: php7.1.8
  • Swoole version: 4.3
  • SMProxy version: 1.2.7

How to Reproduce the Problem? (如何重现问题)

进入smproxy/bin目录执行开启服务
./SMProxy start
可正常访问代理后的服务及数据库。
但执行停止服务
./SMProxy stop
终端提示:SMProxy is stopping ...
等待须久,终端提示:ERROR: SMProxy shutting down failed!
查看swoole.log 并无报错信息,且提示:NOTICE Server is shutdown now.。同时查看进程还在,但无法访问代理服务与数据库了。

求助,插入数据时提示 packets out of order

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: Ubuntu14.04
  • Swoole version: 4.2.5
  • SMProxy version: 1.2.6 beta

How to Reproduce the Problem? (如何重现问题)

  1. 批量插入数据

Expected Behavior (预期行为)

正常插入
...

Actual Behavior (实际行为)

SQLSTATE[08S01]: Communication link failure: 1149 08S01Got packets out of order
...

More Information (更多信息)

不使用SMP时一切正常 单条数据量也没有很大 只是一篇文章
...

Mac上无法启动worker

Describe Your Environment (描述你的环境)

  • System: macOS Mojave 10.14.5
  • PHP version: 7.2.9
  • Swoole version: 4.2.7
  • SMProxy version: 1.2.8

How to Reproduce the Problem? (如何重现问题)

  1. 无法启动worker,调试发现是卡在SMProxyServer->setStartConns里的$client->recv();这一行
    1562834346122

预处理语句错误

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.3
  • Mysql version: 8.0
  • Swoole version: 4.4.3
  • SMProxy version: 1.2.9

How to Reproduce the Problem? (如何重现问题)

1.TP5 框架使用smproxy链接数据库进行插入或者修改操作就会出现
SQLSTATE[HY000]: General error: 1149 HY000Unknown prepared statement handler (2) given to mysql_stmt_precheck 错误
2. 如果在执行这个sql语句的前面先进行一个select操作,则恢复正常。
3.这个情况只有当MySQL版本是8.0才会出现,5.7 是正常。

Expected Behavior (预期行为)

...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

建议作者进行以下检查

  1. Git commit message 中英混合是否不合适?且首行应为本次提交信息的标题。
  2. README Markdown 语法是否太混乱?换行、标题、大小写、语法是否应该修改?
  3. 是否应当编写对应单元测试并确保内存回收没有问题以保证运行稳定?
  4. 是否应当使用守护进程,例如 Supervisor 等方式确保异常退出能够重启?
  5. README 图片是否应当使用稳定的图床或直接保存在 repo 内,例如 doc 文件夹?
  6. README 最后的配置项表格是否存在太多列、难以阅读的问题?
  7. 若考虑向国外用户推广,是否应当准确翻译项目文档?

看好本项目的初衷和效果,但稳定性以及文档质量、代码质量,个人认为还有待提高。

配置设置问题咨询

SMProxy的账号密码端口和ip能设置与原mysql一样的吗?比如都设置为 127.0.0.1 root 123456 3306
目的是为了防止这个访问突然断了后直接连回mysql,或者说这服务有守护进程在的吗?服务挂了会重启或服务器挂了重启它也跟着重启而不需要手动启动

bin/server -c 不携带路径会报 NOTICE

➜  smproxy bin/server -c

PHP Notice:  Undefined offset: 2 in /Users/xxx/web/smproxy/src/Command/Command.php on line 29
PHP Stack trace:
PHP   1. {main}() /Users/xxx/web/smproxy/bin/server:0
PHP   2. SMProxy\Command\Command->run() /Users/xxx/web/smproxy/bin/server:10

Notice: Undefined offset: 2 in /Users/xxx/web/smproxy/src/Command/Command.php on line 29

Call Stack:
    0.0024     391384   1. {main}() /Users/xxx/web/smproxy/bin/server:0
    0.0471    1897160   2. SMProxy\Command\Command->run() /Users/xxx/web/smproxy/bin/server:10

ERROR: No such file or directory!

观察 /Users/xxx/web/smproxy/src/Command/Command.php on line 29 代码发现,应当做好判断。

swFactoryProcess_finish (ERROR 1004): send 122 byte failed, because connection[fd=31487] is closed.

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.2.6
  • Swoole version: 2.2.0
  • SMProxy version: 1.2.7

How to Reproduce the Problem? (如何重现问题)

  1. 在smproxy/logs/swoole.log中出现了许多下面的错误
    NOTICE swFactoryProcess_finish (ERROR 1004): send 122 byte failed, because connection[fd=31487] is closed.

求告知这是怎么造成的,以及如何规避掉这个问题;
在业务访问上,我们也出现了有时候连不上的问题,本以为是是设置的连接数占满的问题,但是在mysql.log中没有出现连接数占满的告警。

...

权限错误

image

权限改成了 644,不可执行,需修改为 755。

SQLSTATE[HY000]: General error: 1149 HY000Lock wait timeout exceeded; try restarting transaction

ubuntu18, PHP7.3,mysql5.7.26 (描述你的环境)

  • System:
  • PHP version: 7.3
  • Mysql version: 5.7.26
  • Swoole version: 4.3.6
  • SMProxy version: 1.2.8
    laravel 5.5

How to Reproduce the Problem? (如何重现问题)

SQLSTATE[HY000]: General error: 1149 HY000Lock wait timeout exceeded; try restarting transaction (SQL: update members_setmeals set setmeal_id = 3, setmeal_name = 季度会员, updated_at = 2019-08-05 10:56:32 where id = 274)

Expected Behavior (预期行为)

进行事物操作,超时
...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

任何出错都把$e中errorInfo的错误码换成了1149

Describe Your Environment (描述你的环境)

  • System: centos7.2
  • PHP version: 7.1.3
  • Mysql version: 5.7
  • Swoole version: 4.3.3
  • SMProxy version: 1.2.8

How to Reproduce the Problem? (如何重现问题)

try {
} catch(Throwable $e){
$e
}

  1. 任何出错都把$e中errorInfo的错误码换成了1149。
    看代码是MysqlProxy -》onClientReceive
    //ERROR Packet
    if ($binaryPacket->data[4] == ErrorPacket::$FIELD_COUNT) {
    $errorPacket = new ErrorPacket();
    $errorPacket->read($binaryPacket);
    $errorPacket->errno = ErrorCode::ER_SYNTAX_ERROR;
    $data = getString($errorPacket->write());
    }
    请问和这样处理,而不是直接转发mysql的错误?

Expected Behavior (预期行为)

mysql的错误码
...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

mysql8.0版本下问题咨询

image
将语句中的 'root'@'%' 替换成你所使用的用户, password 替换成其密码.
我的root用户是只允许127.0.0.1本地访问,我可以设置''root'@'127.0.0.1'吗? PHP项目里都是同一使用的root+127.0.0.1访问数据库,远程连接的有其他账号
如仍无法使用, 应在my.cnf中设置 default_authentication_plugin = mysql_native_password
这个怎么才能知道能不能使用?好像都是能启动服务的

php版本问题

Describe Your Environment (描述你的环境)

  • System:
  • PHP version:
  • Swoole version:
  • SMProxy version:

How to Reproduce the Problem? (如何重现问题)

  1. 我系统上php有两个版本 一个 7.0,一个 5.4 ,,php-v 显示 是 5.4,,我启动 。./bin/SMProxy restart --console 报错,,应该是提示版本错误

Expected Behavior (预期行为)

...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

自动退出

Describe Your Environment (描述你的环境)

  • System: centos
  • PHP version: 7.2
  • Mysql version: 4.3
  • Swoole version: 4.3
  • SMProxy version: 1.25

How to Reproduce the Problem? (如何重现问题)

[2019-07-16 14:41:32 *1195.1] NOTICE swFactoryProcess_finish (ERRNO 1004): send 73 byte failed, because connection[fd=37] is closed
WARNING: Server is shutdown!

Expected Behavior (预期行为)

...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

php 安装版本声明错了

php ./bin/SMProxy
PHP Parse error: syntax error, unexpected '?' in /home/test/SMProxy/vendor/humbug/box/src/FileSystem/file_system.php on line 497
test:~/SMProxy$ php -v
PHP 7.0.30 (cli) (built: Jun 27 2018 09:34:40) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.30, Copyright (c) 1999-2017, by Zend Technologies

bin/server 的帮助信息没有更新

➜  smproxy bin/server

  /$$$$$$  /$$      /$$ /$$$$$$$
 /$$__  $$| $$$    /$$$| $$__  $$
| $$  \__/| $$$$  /$$$$| $$  \ $$ /$$$$$$   /$$$$$$  /$$   /$$ /$$   /$$
|  $$$$$$ | $$ $$/$$ $$| $$$$$$$//$$__  $$ /$$__  $$|  $$ /$$/| $$  | $$
 \____  $$| $$  $$$| $$| $$____/| $$  \__/| $$  \ $$ \  $$$$/ | $$  | $$
 /$$  \ $$| $$\  $ | $$| $$     | $$      | $$  | $$  >$$  $$ | $$  | $$
|  $$$$$$/| $$ \/  | $$| $$     | $$      |  $$$$$$/ /$$/\  $$|  $$$$$$$
 \______/ |__/     |__/|__/     |__/       \______/ |__/  \__/ \____  $$
                                                               /$$  | $$
                                                              |  $$$$$$/
                                                               \______/

SMProxy version: v1.2.1

Options and arguments (and corresponding environment variables):
start   : start server
stop    : stop server
restart : restart server
status  : view service status
reload  : graceful restart
-h      : print this help message and exit (also --help)
-v      : print server version

MariaDB10下问题咨询

Describe Your Environment (描述你的环境)

  • System:
  • PHP version: 7.2
  • Swoole version: 4.2.6
  • SMProxy version: 1.2.7
  • MariaDB 10

How to Reproduce the Problem? (如何重现问题)

  1. 正常查询,sql=show databases

Expected Behavior (预期行为

查询
...

Actual Behavior (实际行为)

Packets out of order. Expected 1 received 2. Packet
mysqli::query(): MySQL server has gone away
...

More Information (更多信息)

尝试用mysql5.7版本一切正常;
测试代码
`$conn = new mysqli('127.0.0.1','root','123456','test',3366);

if($conn->connect_errno){
die('连接错误');
}

$sql = "show databases;";
$res = $conn->query($sql);
print_r($res->fetch_assoc());
$conn->close();`
...

请问这个框架可以适用于多个数据库的情况吗

Describe Your Environment (描述你的环境)

  • System: CentOS6.5
  • PHP version: 7.2
  • Swoole version: 4.3.2
  • SMProxy version: 1.2.7

How to Reproduce the Problem? (如何重现问题)

  1. 项目中使用到了多个数据库,需要根据用户登录信息切换数据库,在对应数据库中进行查询,而数据库信息已经写死在database.json中,想请问有没有办法动态的切换连接的数据库,即连接池中的对象连接的是不同的数据库,另外,数据库也可能动态的增减,除了更新json文件外还有什么方法能支持到这样的需求吗

Expected Behavior (预期行为)

...

Actual Behavior (实际行为)

...

More Information (更多信息)

...

如果数据库和程序不在一个局域网部署

按照这个逻辑的话,如果数据库和程序不在同一个局域网,也会有很好的表现吗?因为只需要程序启动的时候建立一个连接,程序再请求连接池返回的是已经存在的连接,那时间就可以忽略么?

服务启动不了

你好!

Describe Your Environment (描述你的环境)

  • System: centos7
  • PHP version: 7.1
  • Swoole version: 4.2
  • SMProxy version: 1.2.7

How to Reproduce the Problem? (如何重现问题)

./SMProxy start

Expected Behavior (预期行为)

启动服务

Actual Behavior (实际行为)

启动失败,swoole.log NOTICE Server is shutdown now.就出现这一行,其他就没有了,想问下是什么原因或者如何调试??

是否考虑根据配置项选择长连接?

如题,最近刚好接触PHP连接池,拜读了 SMProxy 的代码,发现初始化数据库连接的用的 connect 而不是 pconnect 长连接,是否故意为之?用长连接不是应该能减少重连的性能损耗?后期是否可以根据配置项建立长连接 ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.