swoole / swoole-src

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

"task_id (destination Task Worker Id") in $server->task() is mapping wrongly #4837

Closed fakharak closed 2 years ago

fakharak commented 2 years ago

Please answer these questions before submitting your issue.

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

In Swoole configuration, i configured two Worker processes and four Task Worker processes. So ids of Worker processes is 0 and 1, and Task Worker processes is from 2 to 5. I called $server->task($data, 2, callback() {})

  1. What did you expect to see? I expect that the argument 2 in the $server->task() should map to Task Worker Process with Id 2; the first Task Worker Process.

  2. What did you see instead? The argument 2 in the $server->task() is actually map to Task Worker Process with Id 3; the second Task Worker Process.

In other words, if i pass argument 2 in the call $server->task(), it means second Task Worker having Id as 3, not 'the first Task Worker having Id as 2)

I think the $server->task() should take the actual ID number of the Task Worker, not the number of order of the Task Worker in the list of Task Workers.

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

  2. What is your machine environment used (show your uname -a & php -v & gcc -v) ? Linux (Ubuntu 22.04), PHP version 8.1.10

GCC -V Output;

Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/11/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 11.2.0-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-11/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-11 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --enable-cet --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-11-gBFGDP/gcc-11-11.2.0/debian/tmp-gcn/usr --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2 Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1)

deminy commented 2 years ago

The 2nd argument is the ID of the task worker to which the task is assigned. If it is -1, Swoole will randomly pick an idle task worker.

Please note that task ID starts from 0; it ranges from 0 to $server>setting[\Swoole\Constant::OPTION_TASK_WORKER_NUM] - 1]. For your case, task IDs range from 0 to 3 (four task worker processes in total).