vali 6 년 전
부모
커밋
94bda5fb16
4개의 변경된 파일84개의 추가작업 그리고 14개의 파일을 삭제
  1. 20 3
      datainf/logic/HttpServerDataInf.php
  2. 17 5
      datainf/logic/HttpServerOnlySet.php
  3. 18 2
      datainf/logic/HttpServerRedisToSql.php
  4. 29 4
      datainf/logic/HttpServerSettelement.php

+ 20 - 3
datainf/logic/HttpServerDataInf.php

@@ -25,8 +25,8 @@ class HttpServerDataInf
         $this->httpserver->set($config['sets']);
         $this->config = $config;
 
-        $taskWorkingNum = new \swoole\Atomic();
-        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+        $this->httpserver->account = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = new \swoole\Atomic();
 
         $this->httpserver->on('request', array($this, 'OnRequest'));
         $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
@@ -37,13 +37,28 @@ class HttpServerDataInf
 
     public function onWorkerStart($serv, $worker_id)
     {
+        /*
         $name = $serv->taskworker ? 'Task_' : 'Worker_';
         $name = 'Data_' . $name . ($serv->worker_id < 10 ? '0' . $serv->worker_id : $serv->worker_id);
         swoole_set_process_name($name);
+        */
 
         $GLOBALS['model'] = '';
         $GLOBALS['modeltime'] = 0;
         $this->InitDb();
+
+        if ($serv->worker_id == 0) {
+            \Swoole\Timer::tick(60000, function () {
+                $this->logRunStatus();
+            });
+        }
+
+    }
+
+    private function logRunStatus()
+    {
+        echo date('Y-m-d H:i:s') . " 总请求数:" . $this->httpserver->account->get() . '  运行任务数:' . $this->httpserver->taskWorkingNum->get();
+        echo $this->httpserver->worker_id . " 内存使用量:" . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k\n";
     }
 
 
@@ -52,9 +67,11 @@ class HttpServerDataInf
         $response->header('Content-Type', 'text/html; charset=utf-8');
         $response->header('Server', 'DataInfaceServer');
         $paras = array_merge(['request_time' => date("H:i:s")], !empty($request->get) ? $request->get : [], !empty($request->post) ? $request->post : []);
+        $this->httpserver->account->add();
+
 
         $request_uri = substr($request->server['request_uri'], 1);
-        $urls = ['setLeague', 'setMatch', 'setMatchResult', 'setOdds', 'setOddsCH', 'setBroadCast','upMatch'];
+        $urls = ['setLeague', 'setMatch', 'setMatchResult', 'setOdds', 'setOddsCH', 'setBroadCast', 'upMatch'];
 
         if (!in_array($request_uri, $urls)) {
             $data = Response::generate('', 0, '', '无效的url');

+ 17 - 5
datainf/logic/HttpServerOnlySet.php

@@ -40,8 +40,8 @@ class HttpServerOnlySet
         $this->config = $config;
         $this->redisconfig = GlobConfigs::getKey('redis');
 
-        $taskWorkingNum = new \swoole\Atomic();
-        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+        $this->httpserver->account = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = new \swoole\Atomic();
 
         $this->httpserver->on('request', array($this, 'OnRequest'));
         $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
@@ -60,12 +60,23 @@ class HttpServerOnlySet
 
         Swoole\Timer::tick(1000, function () {
             $this->TaskSQlToRedis();
-            if (memory_get_usage() >= 5000000) {
-                echo $this->httpserver->worker_id . ' 内存使用:' . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k \n";
-            }
         });
+
+        if ($serv->worker_id == 0) {
+            Swoole\Timer::tick(60000, function () {
+                $this->logRunStatus();
+            });
+        }
+
     }
 
+    private function logRunStatus()
+    {
+        echo date('Y-m-d H:i:s') . " 总请求数:" . $this->httpserver->account->get() . '  运行任务数:' . $this->httpserver->taskWorkingNum->get();
+        echo $this->httpserver->worker_id . " 内存使用量:" . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k\n";
+    }
+
+
     private function getRedis()
     {
         if (time() - $this->redisTime <= 60 * 30) {
@@ -237,6 +248,7 @@ class HttpServerOnlySet
         try {
             $ret = $this->getRedis()->rpop(self::TASKQNUM);
             if (!empty($ret)) {
+                $this->httpserver->account->add();
                 $this->doSettelement($ret);
             }
         } catch (\Exception $e) {

+ 18 - 2
datainf/logic/HttpServerRedisToSql.php

@@ -30,8 +30,8 @@ class HttpServerRedisToSql
 
         $this->redisonfig = GlobConfigs::getKey('redis');
 
-        $taskWorkingNum = new \swoole\Atomic();
-        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+        $this->httpserver->account = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = new \swoole\Atomic();
 
         $this->httpserver->on('request', array($this, 'OnRequest'));
         $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
@@ -40,6 +40,7 @@ class HttpServerRedisToSql
 
     }
 
+
     public function onWorkerStart($serv, $worker_id)
     {
         if (!$serv->taskworker) {
@@ -51,8 +52,21 @@ class HttpServerRedisToSql
             });
         }
 
+        if ($serv->worker_id == 0) {
+            Swoole\Timer::tick(60000, function () {
+                $this->logRunStatus();
+            });
+        }
+
     }
 
+    private function logRunStatus()
+    {
+        echo date('Y-m-d H:i:s') . " 总请求数:" . $this->httpserver->account->get() . '  运行任务数:' . $this->httpserver->taskWorkingNum->get();
+        echo $this->httpserver->worker_id . " 内存使用量:" . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k\n";
+    }
+
+
     //sql批量写入数据库
     private function BatchSqlRedisToDB()
     {
@@ -65,6 +79,8 @@ class HttpServerRedisToSql
                 return;
             }
 
+            $this->httpserver->account->add();
+
             $batchsql = [];
             $max = 5000;
 

+ 29 - 4
datainf/logic/HttpServerSettelement.php

@@ -37,8 +37,8 @@ class HttpServerSettelement
         $this->dbpooleconfig = GlobConfigs::getKey('pgsqlpoole');
         $this->redisonfig = GlobConfigs::getKey('redis');
 
-        $taskWorkingNum = new \swoole\Atomic();
-        $this->httpserver->taskWorkingNum = $taskWorkingNum;
+        $this->httpserver->account = new \swoole\Atomic();
+        $this->httpserver->taskWorkingNum = new \swoole\Atomic();
 
         $this->httpserver->on('request', array($this, 'OnRequest'));
         $this->httpserver->on('WorkerStart', array($this, 'onWorkerStart'));
@@ -63,6 +63,19 @@ class HttpServerSettelement
         if (!$serv->taskworker) {
             $this->InitDb();
         }
+        if ($serv->worker_id == 0) {
+            \Swoole\Timer::tick(60000, function () {
+                $this->logRunStatus();
+            });
+        }
+
+    }
+
+
+    private function logRunStatus()
+    {
+        echo date('Y-m-d H:i:s')." 总请求数:" . $this->httpserver->account->get() . '  运行任务数:' . $this->httpserver->taskWorkingNum->get();
+        echo $this->httpserver->worker_id . " 内存使用量:" . (memory_get_usage() / 1000) . 'k  峰值:' . (memory_get_peak_usage() / 1000) . "k\n";
     }
 
 
@@ -75,8 +88,11 @@ class HttpServerSettelement
         $request_uri = substr($request->server['request_uri'], 1);
         $urls = ['WinFail', 'Settelement'];
 
+        $this->httpserver->account->add();
+
         echo "现在任务数:" . $this->httpserver->taskWorkingNum->get() . "\n";
 
+
         if (!in_array($request_uri, $urls)) {
             $data = Response::generate('', 0, '', '无效的url');
             $response->end($data);
@@ -130,6 +146,8 @@ class HttpServerSettelement
     //胜负计算
     private function doWinFailse($request, $response, $paras)
     {
+        $this->httpserver->taskWorkingNum->add();
+
         $logic_obj = new WinfailLogic();
         $notice = isset($paras['noticeid']) ? $paras['noticeid'] : 0;
         $id = intval($notice);
@@ -178,12 +196,17 @@ class HttpServerSettelement
             $response->end($data);
             return;
         }
+
+        $this->httpserver->taskWorkingNum->sub();
+
         return;
     }
 
 
     private function doSettelementIntoRedis($request, $response, $paras)
     {
+        $this->httpserver->taskWorkingNum->add();
+
         try {
             list($order_ids, $bettype, $settype, $game_code, $match_id, $change_status) = $this->requestpara($request, $response, $paras);
 
@@ -230,14 +253,16 @@ class HttpServerSettelement
             LABRETURN:
             $data = Response::generate('', 1, ['cost' => (microtime(true) - $request->server['request_time_float'])], 'succes ');
             $response->end($data);
-            return;
+
         } catch (\Exception $e) {
 
             $data = Response::generate('', 10, '', $e->getMessage() . '--' . $e->getFile() . '--' . $e->getLine());
             $response->end($data);
             unset($data);
-            return;
+
         }
+
+        $this->httpserver->taskWorkingNum->sub();
     }
 
     private function requestpara($request, $response, $paras)