swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.42k stars 3.16k forks source link

PDO Postgres coroutine not working #2051

Closed codeliner closed 5 years ago

codeliner commented 5 years ago

Please answer these questions before submitting your issue. Thanks!

  1. What did you do? If possible, provide a simple script for reproducing the error.

I tried the Coroutine feature available since swoole 4.1 for PDO. I run a test against MySql server and it works like expected. I run the same test against PostgreSQL server and PDO query is blocking.

You can find the test here: https://github.com/proophsoftware/swoole-mongo-test#set-up

  1. What did you expect to see?

I have a Swoole Http Server running with only one worker. One request uses PDO to perform a slow query (simulated with a sleep select query) that takes 10 seconds. My expectation is that even if the query takes 10 seconds other requests are served just fine due to Coroutines enabled.

  1. What did you see instead?

MySql works like a charm but PostgreSQL query is blocking. Hence, parallel requests are not served until query resolves.

  1. What version of Swoole are you using (show your php --ri swoole)?
swoole

swoole support => enabled
Version => 4.1.2
Author => Swoole Group[email: team@swoole.com]
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
spinlock => enabled
rwlock => enabled
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.aio_thread_num => 2 => 2
swoole.display_errors => On => On
swoole.use_namespace => On => On
swoole.use_shortname => On => On
swoole.fast_serialize => Off => Off
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (including version of kernel & php & gcc) ?

The Swoole server runs in a docker container: prooph/php:7.2-cli

codeliner commented 5 years ago

Got a hint in the linked zend-expressive-swoole issue (see above) that the Chinese docs contain an unavailable list. An English version (translated with google translate) can be found here: https://translate.google.com/translate?hl=de&sl=auto&tl=en&u=https%3A%2F%2Fwiki.swoole.com%2Fwiki%2Fpage%2F965.html

Can we expect that PDO PostgeSQL will work in a future version of Swoole?

twose commented 5 years ago

Well, there is a reason for that, the lib must be implemented by php_stream then we can hook it. But, not everything has good luck, some useful libs have not used it, we have the other way to hook it, but more complicated. You can see: https://wiki.swoole.com/wiki/page/983.html

codeliner commented 5 years ago

thx for the explanation and hint @twose

I close the issue. Keep on the good work!

linuxd3v commented 4 months ago

if I understand it correctly - the swoole 5.1.0 added support for pdo postgres coroutines: https://pecl.php.net/package-info.php?package=swoole&version=5.1.0

https://github.com/swoole/swoole-src/releases/tag/v5.1.0