Giter Club home page Giter Club logo

Comments (5)

roverliang avatar roverliang commented on July 28, 2024

你的协程数量开太多了,超过了当前脚本的最大申请内存限制,要在当前脚本设定协程的数量。
\Swoole\Coroutine::set([ 'max_coroutine' => 1000, ]);
并且在启动协程的地方添加休息时间,防止系统过载:

$coroutineStat = \Swoole\Coroutine::stats(); if ($coroutineStat['coroutine_num'] >= 100) { \Swoole\Coroutine::sleep(1); }
希望能够交流下,我近几天,也为这个问题困扰。我不知道这是不是一个好的解决方案,期望有大神可以回复下。

from saber.

roverliang avatar roverliang commented on July 28, 2024
go(function () use ($host, $port, $poolSize, $queueKey) {
    $pool = new DotCloud\RedisPool($host, $port, $poolSize);
    while (true) {
        $redis = $pool->get();
        if ($redis->lLen($queueKey) > 0) {
            $data = $redis->rPop($queueKey);
            if (empty($data)) {
                $pool->put($redis);
                continue;
            }
            // ......
            // redis 里取出数据[ ['uri'=> ''], ['uri'=> ''] ],使用requests并发请求
            $responses = Swlib\SaberGM::requests($urls);
            // ......
        }
        $pool->put($redis);
    }
});
# php --ri swoole

swoole

swoole support => enabled
Version => 4.2.9
Author => Swoole Group[email: [email protected]]
coroutine => enabled
debug => enabled
trace_log => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.0.2k-fips  26 Jan 2017
http2 => 1.31.1
pcre => enabled
zlib => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => 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
# cat /var/log/messages | grep swoole
Dec  3 11:06:01 izwz99ilp8qh025s8ak1y9z kernel: php[12589]: segfault at 8 ip 00007fdd0544409b sp 00007fdd04f9fed0 error 4 in swoole.so[7fdd053c9000+132000]
Dec  3 13:40:32 izwz99ilp8qh025s8ak1y9z kernel: php[16214]: segfault at 8 ip 00007fd42a84409b sp 00007fd42a39fed0 error 4 in swoole.so[7fd42a7c9000+132000]

# uname -a
Linux izwz99ilp8qh025s8ak1y9z 3.10.0-693.2.2.el7.x86_64 #1 SMP Tue Sep 12 22:26:13 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

# php -v
PHP 7.1.24 (cli) (built: Nov  7 2018 18:08:20) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.24, Copyright (c) 1999-2018, by Zend Technologies

# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC)

你的协程数量开太多了,超过了当前脚本的最大申请内存限制,要在当前脚本设定协程的数量。
`
\Swoole\Coroutine::set([ 'max_coroutine' => 1000, ]);

并且在启动协程的地方添加休息时间,防止系统过载:
$coroutineStat = \Swoole\Coroutine::stats();
if ($coroutineStat['coroutine_num'] >= 100) { \Swoole\Coroutine::sleep(1); }
`
希望能够交流下,我近几天,也为这个问题困扰。我不知道这是不是一个好的解决方案,期望有大神可以回复下。

from saber.

springleng avatar springleng commented on July 28, 2024

@roverliang #2175 帖子也发这里了,你可以看看,目前想跟踪这个问题还跟踪不到,不跟踪的时候就出现了

from saber.

springleng avatar springleng commented on July 28, 2024

@roverliang 应该不是你说的这个问题了,我这个数字一直都是1

array(3) {
  ["stack_size"]=>
  int(8192)
  ["coroutine_num"]=>
  int(1)
  ["coroutine_peak_num"]=>
  int(1)
}

from saber.

twose avatar twose commented on July 28, 2024

@roverliang 不知道你说的问题是什么, 协程不会过载

from saber.

Related Issues (20)

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.