{"action":"created","issue":{"url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/28","repository_url":"https://api.github.com/repos/zendframework/zend-expressive-swoole","labels_url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/28/comments","events_url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/28/events","html_url":"https://github.com/zendframework/zend-expressive-swoole/pull/28","id":355982579,"node_id":"MDExOlB1bGxSZXF1ZXN0MjEyMzg0OTMx","number":28,"title":"Added support of Swoole 4.1 coroutine","user":{"login":"huangzhhui","id":12077148,"node_id":"MDQ6VXNlcjEyMDc3MTQ4","avatar_url":"https://avatars1.githubusercontent.com/u/12077148?v=4","gravatar_id":"","url":"https://api.github.com/users/huangzhhui","html_url":"https://github.com/huangzhhui","followers_url":"https://api.github.com/users/huangzhhui/followers","following_url":"https://api.github.com/users/huangzhhui/following{/other_user}","gists_url":"https://api.github.com/users/huangzhhui/gists{/gist_id}","starred_url":"https://api.github.com/users/huangzhhui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huangzhhui/subscriptions","organizations_url":"https://api.github.com/users/huangzhhui/orgs","repos_url":"https://api.github.com/users/huangzhhui/repos","events_url":"https://api.github.com/users/huangzhhui/events{/privacy}","received_events_url":"https://api.github.com/users/huangzhhui/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-08-31T13:33:34Z","updated_at":"2018-08-31T14:10:05Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/pulls/28","html_url":"https://github.com/zendframework/zend-expressive-swoole/pull/28","diff_url":"https://github.com/zendframework/zend-expressive-swoole/pull/28.diff","patch_url":"https://github.com/zendframework/zend-expressive-swoole/pull/28.patch"},"body":"Swoole 4.1 is ready, there's a incredible feature that could let PDO, Mysqli, redis, soap, stream_socket_client, fsockopen,file_get_contents (Most of I/O driver) become a non-blocking async client needs just one line code `Swoole\\Runtime::enableCorotuine()`.\r\n\r\n> Notice that the documents in swoole official site about coroutine are outdated, I have been contacted with swoole developer team.\r\n\r\n- [x] Are you creating a new feature?\r\n  - [x] Why is the new feature needed? What purpose does it serve?\r\nThe server still running in I/O blocking driver before, even using swoole, when the  request handler processing in I/O request, like DB, Cache request, it will block the hold process, if the server running in 4 workers, and per request consumes 1 sec, the QPS is 4/sec, But, when running in coroutine, all I/O will switch to Non-Blocking driver, the QPS will be unlimited (Actually limited by memory of server, and limited by MySQL or Redis etc.).\r\n  - [x] How will users use the new feature?\r\n```\r\n[\r\n    'zend-expressive-swoole' => [\r\n        'swoole-http-server' => [\r\n            'options' => [\r\n                'enable_coroutine' => true,\r\n            ],\r\n        ],\r\n    ]\r\n]\r\n```\r\n  - [x] Base your feature on the `master` branch, and submit against that branch.\r\n  - [x] Add only one feature per pull request; split multiple features over multiple pull requests\r\n\r\nI make some tests, the results are below, server running in coroutine mode about **1350 times** fater than non-coroutine mode.\r\n> The tests result maybe wrong, because my MySQL server cannot handle the huge connection numbers like this, I have to develop a Connection Pool before this, anyone could provide another tests result would be better, but coroutine still faster than non-coroutine is a fact.\r\nI write the code in a Controller as below.\r\n```\r\n$pdo = new \\PDO($dsn, $user, $password);\r\n$pdo->query('select sleep(1)');\r\n```\r\nAnd then run the server in `non-coroutine` mode and `coroutine` mode.\r\nStress testing command: `ab -k -c 1000 -t 10 http://127.0.0.1:9501/`\r\n\r\nNon-Coroutine mode:\r\n![_ _20180831204013](https://user-images.githubusercontent.com/12077148/44915223-0317e580-ad65-11e8-8797-4ba44c40ac94.png)\r\n\r\n\r\nCoroutine mode:\r\n![_ _20180831203911](https://user-images.githubusercontent.com/12077148/44915236-0a3ef380-ad65-11e8-8351-96889115be7b.png)\r\n"},"comment":{"url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/comments/417676229","html_url":"https://github.com/zendframework/zend-expressive-swoole/pull/28#issuecomment-417676229","issue_url":"https://api.github.com/repos/zendframework/zend-expressive-swoole/issues/28","id":417676229,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNzY3NjIyOQ==","user":{"login":"huangzhhui","id":12077148,"node_id":"MDQ6VXNlcjEyMDc3MTQ4","avatar_url":"https://avatars1.githubusercontent.com/u/12077148?v=4","gravatar_id":"","url":"https://api.github.com/users/huangzhhui","html_url":"https://github.com/huangzhhui","followers_url":"https://api.github.com/users/huangzhhui/followers","following_url":"https://api.github.com/users/huangzhhui/following{/other_user}","gists_url":"https://api.github.com/users/huangzhhui/gists{/gist_id}","starred_url":"https://api.github.com/users/huangzhhui/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huangzhhui/subscriptions","organizations_url":"https://api.github.com/users/huangzhhui/orgs","repos_url":"https://api.github.com/users/huangzhhui/repos","events_url":"https://api.github.com/users/huangzhhui/events{/privacy}","received_events_url":"https://api.github.com/users/huangzhhui/received_events","type":"User","site_admin":false},"created_at":"2018-08-31T14:10:05Z","updated_at":"2018-08-31T14:10:05Z","author_association":"CONTRIBUTOR","body":"@ezimuel There is the only official documents for reference, but it's Chinese, maybe you should translate it.\r\nhttps://wiki.swoole.com/wiki/page/965.html"}}
{"actor":{"display_login":"huangzhhui"}}