@@ -452,11 +452,11 @@ pid_t ProcessPool::spawn(Worker *worker) {
452452 switch (pid) {
453453 // child
454454 case 0 :
455+ worker->init ();
455456 worker->pid = SwooleG.pid ;
456457 swoole_set_process_type (SW_PROCESS_WORKER);
457458 swoole_set_process_id (worker->id );
458459 SwooleWG.worker = worker;
459- SwooleWG.run_always = true ;
460460 if (async) {
461461 if (swoole_event_init (SW_EVENTLOOP_WAIT_EXIT) < 0 ) {
462462 exit (254 );
@@ -987,11 +987,7 @@ void ProcessPool::destroy() {
987987 sw_mem_pool ()->free (workers);
988988}
989989
990- bool Worker::has_exceeded_max_request () {
991- return !SwooleWG.run_always && request_count >= SwooleWG.max_request ;
992- }
993-
994- void Worker::start () {
990+ void Worker::init () {
995991 start_time = ::time (nullptr );
996992 request_count = 0 ;
997993 set_status_to_idle ();
@@ -1000,15 +996,14 @@ void Worker::start() {
1000996}
1001997
1002998void Worker::set_max_request (uint32_t max_request, uint32_t max_request_grace) {
1003- if (max_request < 1 ) {
1004- SwooleWG.run_always = true ;
1005- } else {
1006- SwooleWG.run_always = false ;
1007- SwooleWG.max_request = max_request;
1008- if (max_request_grace > 0 ) {
1009- SwooleWG.max_request += swoole_system_random (1 , max_request_grace);
1010- }
999+ if (max_request > 0 && max_request_grace > 0 ) {
1000+ max_request += swoole_system_random (1 , max_request_grace);
10111001 }
1002+ SwooleWG.max_request = max_request;
1003+ }
1004+
1005+ bool Worker::has_exceeded_max_request () {
1006+ return SwooleWG.max_request > 0 && request_count >= SwooleWG.max_request ;
10121007}
10131008
10141009void Worker::shutdown () {
0 commit comments