stanley-king 2 rokov pred
rodič
commit
e5a24a74be

+ 1 - 1
docker/compose/xyz/worker/docker-compose.yml

@@ -14,7 +14,7 @@ services:
     deploy:
       resources:
         limits:
-          cpus: '8'
+          cpus: '1'
 
   queuesrv:
     image: php-zts-debug:7.3.18

+ 2 - 9
helper/refill/RefillBase.php

@@ -892,19 +892,12 @@ class RefillBase
     {
         $this->mPolicy->update_mchratios($gross,$detail);
     }
-
     public function UpdateChctl($params)
     {
         $this->mPolicy->update_chctl($params);
     }
-
-    //todo delete down lines
-    public function UpdateRatio($ratios)
-    {
-        $this->mPolicy->update_ratios($ratios);
-    }
-    public function UpdateSpeeds($speeds)
+    public function UpdateMaxSpeed($params)
     {
-        $this->mPolicy->update_chspeeds($speeds);
+        $this->mPolicy->update_maxspeeds($params);
     }
 }

+ 1 - 2
helper/refill/policy/IPolicy.php

@@ -16,8 +16,7 @@ interface IPolicy
     public function need_intercept($mchid,$card_type,$card_state,$is_transfer,$card_no) : bool;
     public function region_intercept($quality,$card_type,$region_no) : bool;
 
-    public function update_ratios($ratios);
     public function update_mchratios($all,$detail);
-    public function update_chspeeds($speeds);
     public function update_chctl($speeds);
+    public function update_maxspeeds($speeds);
 }

+ 22 - 4
helper/refill/policy/chctlex.php

@@ -110,6 +110,23 @@ class chctlex
         }
     }
 
+    public function update_maxspeeds($params)
+    {
+        foreach ($params as $key => $val)
+        {
+            [$name, $spec, $card_type] = explode('-', $key);
+
+            $quality = $this->mNameMapQuality["{$name}-{$card_type}-{$spec}"] ?? 0;
+            if ($quality <= 0) continue;
+
+            $prefix = $this->prefix($name,$spec,$card_type,$quality);
+            $ctl = $this->mSpeedtable[$prefix] ?? null;
+            if(is_null($ctl)) continue;
+
+            $ctl->update_maxspeeds($val);
+        }
+    }
+
     public function match($names, int $spec, int $card_type, int $quality, $max_inprice)
     {
         $trace = new scope_trace(__METHOD__);
@@ -292,10 +309,11 @@ class chctlex
             foreach ($ctls as $item)
             {
                 Log::record("ctl_splitor {$item->name()} speed={$item->cur_speed()} max_speed={$item->max_speed()}",Log::DEBUG);
-                if($item->need_feed()) {
-                    $feeds[] = $item;
-                }
-                elseif($item->speed_overload()) {
+//                if($item->need_feed()) {
+//                    $feeds[] = $item;
+//                }
+//                else
+                if($item->speed_overload()) {
                     $overs[] = $item;
                 }
                 else {

+ 6 - 14
helper/refill/policy/ctl_itemex.php

@@ -4,8 +4,6 @@ namespace refill;
 
 class ctl_itemex
 {
-    const feed_threshold = 2;
-
     private $mName;
     private $mCardType;
     private $mAmount;
@@ -52,12 +50,10 @@ class ctl_itemex
     {
         return $this->mName;
     }
-
     public function priority()
     {
         return $this->mPriority;
     }
-
     public function storge()
     {
         return $this->mStorge;
@@ -97,21 +93,22 @@ class ctl_itemex
             $this->mNotifyTime = 300;
         }
     }
+    public function update_maxspeeds($speed)
+    {
+        $this->mMaxSpeed = $speed;
+    }
     public function max_speed()
     {
         return $this->mMaxSpeed;
     }
     public function speed_overload(): bool
     {
-        if ($this->mMaxSpeed < 0) {
-            return false;
-        } elseif ($this->mMaxSpeed == 0) {
+        if ($this->mMaxSpeed == 0) {
             return true;
         } else {
             return $this->mSpeed >= $this->mMaxSpeed;
         }
     }
-
     public function cur_speed()
     {
         return $this->mSpeed;
@@ -127,13 +124,8 @@ class ctl_itemex
     }
     public function need_feed()
     {
-        if(self::feed_threshold >= $this->mMaxSpeed) {
-            return $this->mMonitorCommit < $this->mMaxSpeed;
-        } else {
-            return $this->mMonitorCommit < self::feed_threshold;
-        }
+        return $this->mMonitorCommit < $this->mMaxSpeed;
     }
-
     public function compile_val($profit_ratio)
     {
         $time_factor = 60;

+ 1 - 8
helper/refill/policy/lingzh/policy.php

@@ -482,16 +482,9 @@ class policy extends ProviderManager implements IPolicy
         Log::record("notify body={$body}",Log::DEBUG);
         return strtoupper(md5($body));
     }
-    public function update_ratios($ratios)
-    {
-        $this->mChannelControl->update_ratios($ratios);
-    }
+
     public function update_mchratios($gross,$detail)
     {
         $this->mRatioCtl->update($gross,$detail);
     }
-    public function update_chspeeds($speeds)
-    {
-        $this->mChannelControl->update_speeds($speeds);
-    }
 }

+ 4 - 9
helper/refill/policy/xyz/policy.php

@@ -618,22 +618,17 @@ class policy extends ProviderManager implements IPolicy
         return $this->mGlobalInterceptor->isIntercept($quality,$card_type,$region_no);
     }
 
-    public function update_ratios($ratios)
-    {
-        $this->mChannelControl->update_ratios($ratios);
-    }
-
     public function update_mchratios($gross,$detail)
     {
         $this->mRatioCtl->update($gross,$detail);
     }
 
-    public function update_chspeeds($speeds)
-    {
-        $this->mChannelControl->update_speeds($speeds);
-    }
     public function update_chctl($params)
     {
         $this->mChannelControl->update_chctl($params);
     }
+    public function update_maxspeeds($speeds)
+    {
+        $this->mChannelControl->update_maxspeeds($speeds);
+    }
 }

+ 10 - 0
rdispatcher/codispatcher.php

@@ -104,6 +104,16 @@ function subscribe_message(&$quit, &$redis, $channels)
 
                         refill\RefillFactory::instance()->UpdateChctl($params);
                     }
+                    elseif($type == 'channel_speed') {
+                        $ins = Cache::getInstance('cacheredis');
+                        $content = $ins->get_org('refill_channel_control_speed');
+
+                        if(empty($content)) continue;
+                        $params = json_decode($content,true);
+                        if(empty($params)) continue;
+
+                        refill\RefillFactory::instance()->UpdateMaxSpeed($params);
+                    }
                     else {
                         //Log::record("subscribe_message dont not handle mgs:{$sub_type}-{$channel}-{$type}",Log::DEBUG);
                     }

+ 9 - 0
test/TestBigData.php

@@ -115,6 +115,15 @@ class TestBigData extends TestCase
         refill\RefillFactory::instance()->UpdateChctl($data);
     }
 
+    public function testChannelMaxSpeed()
+    {
+        $ins = Cache::getInstance('cacheredis');
+        $content = $ins->get_org('refill_channel_control_speed');
+
+        $data = json_decode($content,true);
+        refill\RefillFactory::instance()->UpdateMaxSpeed($data);
+    }
+
     public function testMtrand()
     {
         $feeds = [1, 2, 3, 4, 5];