-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 6.0: added multi thread supports (#5320)
* Optimize code * thread local * swoole thread * optimize argv * optimize code, add more methods for thread * Swoole\Thread\Map * Swoole\Thread\ArrayList * Optimize * zend_array * Optimize * Optimize * Optimize * fix * remove co redis/mysql/pgsql client * Added Thread\Queue * Fix Thread\Queue * fix mem leak * optimize, reduce memory copy * Revert "optimize, reduce memory copy" This reverts commit 449adf9. * optimize code, remove 8.0 supports * refactor atomic/lock, support thread * clang-format * fix tests * [6.0] Server for thread mode (#5282) * http server for thread mode * fix compile error * optimize code * optimize code * optimize code[2] * optimize code[3] * optimize code[4] * refactor co-socket, support thread * add signal example --------- Co-authored-by: NathanFreeman <[email protected]> * Update version * Optimize header * Fix * refactor async-threads, support ZTS * Optimize * Optimize * Optimize * Optimize * Optimize 5 * Optimize 6 * Optimize 7 * Optimize 8 * Optimize 10 * Optimize 11, add Server::get_worker_id() * Optimize 12 * Optimize 13 * Optimize 14 * rename * Refactor * Refactor 2 * revert , format * onPipeMessage/onTask/onFinish, fix message bus * Update README.md * Added pty support for proc_open function, fix #5275 (#5290) * support pty, fix #5275 * fix * fix 2 * fix * fix BC * fix tests * Update boost asm (#5291) * update boost asm * Fix error * fix tests * fix tests * fix tests * remove hiredis * fix tests [3] * fix tests [4] * fix tests [5], revert SwooleWG * fix tests [6] * fix tests [7] * fix tests [8] * optimize tests * add thread test * fix ci * [test] fix ci 2 * [test] fix ci 3 * [test] fix ci 4 * [test] fix ci 5 * [test] fix ci 6 * [test] fix ci 7 * [test] fix ci 8 * [test] fix ci 9 * [test] fix ci 10 * [test] fix ci 11 * [test] remove swoole_timer_set, async settings can only be set in the main thread * optimize create socket (#5293) * optimize create socket * fix error * optimize code * [test] fix tests * [test] fix tests [3] * [test] fix tests [4] * sync plain_wrapper (#5296) * [test] fix tests [5] * No limit on the maximum buffer length of the read pipeline * Refactor * fix * optimize tests * fix tests * code format * fix tests * fix tests * fix tests [3] * Fix transfer_t struct missing (#5303) * Fix missing transfer_t * Fix missing transfer_t * Optimize thread context * Fix tests[4] * Refactor * Refactor * Refactor * fix server shutdown * fix thread atomic * fix core tests * Fix Sqlite pdo segmentfault (#5311) * fix pdo * fix sqlite error * fix sqlite error * fix sqlite error * fix core tests * Support passing streams between threads * Support using stream as a thread argument * optimize code * optimize code --------- Co-authored-by: NathanFreeman <[email protected]> Co-authored-by: MARiA so cute <[email protected]>
- Loading branch information
1 parent
dd6e0db
commit ef7f7ed
Showing
290 changed files
with
6,648 additions
and
18,680 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Thread Support Tests | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test-linux: | ||
runs-on: ubuntu-latest | ||
if: "!contains(github.event.head_commit.message, '[nts]')" | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: ['8.1-zts', '8.2-zts', '8.3-zts'] | ||
name: ${{ matrix.php }} | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: "${{ matrix.php }}" | ||
coverage: none | ||
env: | ||
phpts: ts | ||
- name: Show machine information | ||
run: | | ||
date | ||
env | ||
uname -a | ||
ulimit -a | ||
php -v | ||
php --ini | ||
ls -al | ||
pwd | ||
echo "`git log -20 --pretty --oneline`" | ||
echo "`git log -10 --stat --pretty --oneline`" | ||
- name: Run Swoole test | ||
run: | | ||
export SWOOLE_BRANCH=${GITHUB_REF##*/} | ||
export SWOOLE_THREAD=1 | ||
export SWOOLE_BUILD_DIR=$(realpath .) | ||
export PHP_VERSION=${{ matrix.php }} | ||
${SWOOLE_BUILD_DIR}/scripts/route.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Swoole\Thread; | ||
use Swoole\Thread\Queue; | ||
|
||
|
||
$args = Thread::getArguments(); | ||
$c = 4; | ||
$running = true; | ||
|
||
if (empty($args)) { | ||
$threads = []; | ||
$atomic = new Swoole\Thread\Atomic(); | ||
for ($i = 0; $i < $c; $i++) { | ||
$threads[] = Thread::exec(__FILE__, $i, $atomic); | ||
} | ||
for ($i = 0; $i < $c; $i++) { | ||
$threads[$i]->join(); | ||
} | ||
var_dump($atomic->get()); | ||
sleep(2); | ||
|
||
Co\run(function () use($atomic) { | ||
$n = 1024; | ||
while ($n--) { | ||
$atomic->add(); | ||
$rs = \Swoole\Coroutine\System::readFile(__FILE__); | ||
var_dump(strlen($rs)); | ||
} | ||
}); | ||
var_dump($atomic->get()); | ||
} else { | ||
$atomic = $args[1]; | ||
Co\run(function () use($atomic) { | ||
$n = 1024; | ||
while ($n--) { | ||
$atomic->add(); | ||
$rs = \Swoole\Coroutine\System::readFile(__FILE__); | ||
var_dump(strlen($rs)); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
use Swoole\Thread; | ||
|
||
$args = Thread::getArguments(); | ||
|
||
if (empty($args)) { | ||
var_dump($GLOBALS['argv']); | ||
$thread = Thread::exec(__FILE__, 'thread-1', $argc, $argv); | ||
$thread->join(); | ||
} else { | ||
var_dump($args[0], $args[1], $args[2]); | ||
sleep(1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
ini_set('memory_limit', '2G'); | ||
$dict = []; | ||
const COUNT = 10000000; | ||
|
||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$dict['key-' . $n] = $n * 3; | ||
} | ||
echo 'array set: ' . round(microtime(true) - $s, 6) . ' seconds' . PHP_EOL; | ||
|
||
$c = 0; | ||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$c += $dict['key-' . $n]; | ||
} | ||
echo 'array get: ' . round(microtime(true) - $s, 6) . ' seconds' . PHP_EOL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
use Swoole\Thread; | ||
use Swoole\Thread\Atomic; | ||
use Swoole\Thread\Atomic\Long; | ||
|
||
$args = Thread::getArguments(); | ||
$c = 4; | ||
$n = 128; | ||
|
||
if (empty($args)) { | ||
$threads = []; | ||
$a1 = new Atomic; | ||
$a2 = new Long; | ||
for ($i = 0; $i < $c; $i++) { | ||
$threads[] = Thread::exec(__FILE__, $i, $a1, $a2); | ||
} | ||
for ($i = 0; $i < $c; $i++) { | ||
$threads[$i]->join(); | ||
} | ||
var_dump($a1->get(), $a2->get()); | ||
} else { | ||
$a1 = $args[1]; | ||
$a2 = $args[2]; | ||
|
||
$a1->add(3); | ||
$a2->add(7); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
ini_set('memory_limit', '2G'); | ||
$args = Swoole\Thread::getArguments(); | ||
|
||
$dict = $args[1]; | ||
const COUNT = 10000000; | ||
|
||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$dict['key-' . $n] = $n * 3; | ||
} | ||
echo $args[0] . "\t" . 'array set: ' . round(microtime(true) - $s, 6) . ' seconds' . PHP_EOL; | ||
|
||
$c = 0; | ||
$n = COUNT; | ||
$s = microtime(true); | ||
while ($n--) { | ||
$c += $dict['key-' . $n]; | ||
} | ||
echo $args[0] . "\t" . 'array get: ' . round(microtime(true) - $s, 6) . ' seconds' . PHP_EOL; |
Oops, something went wrong.