PHP异步多线程卷曲应用程序

如何解决PHP异步多线程卷曲应用程序

我正在寻找一个每秒可以处理至少300-400个事务的进程/脚本。 目前,我正在使用Workerman进行以下工作。我可以运行400个线程而没有任何问题,但是tps大约是60-70 tps,可以处理不到一秒的延迟。

下面是工作代码:-

main.php:-

<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;

$http_worker = new Worker('http://0.0.0.0:2345');

$http_worker->count = 400;
$http_worker->onMessage = function ($connection,$request) {
//Config
    $connection->send("");
    $url = 'http://localhost:3000';
    $packageid=11;
    $payload = $request->post();
    $temp_payload = implode("|",$payload);
    list($id,$user,$package_id,$timestamp) = explode('|',$temp_payload);

    $date_request_first=date('Y-m-d H:i:s');// PHP Worker current casting timestamp
    $date_compare1= date("Y-m-d h:i:s a",strtotime($date_request_first));
    
    $xml_get_subscriber='<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ><SOAP-ENV:Body>
    <ns2:root>
        <msg_head>
            <time>2020-08-20 17:57:29</time>
            <from />
            <to />
            <msg_type />
            <serial />
        </msg_head>
        <interface_msg>
            <msg_response>
                <ResponseClass Name="Response">
                    <GetUserClass Name="AJAX">
                        <ResultCode>0</ResultCode>
                        <ResultDescr>success</ResultDescr>
                        <IBAN>'.$id.'</IBAN>
                        <PREFERNOTIFYMETHOD>1</PREFERNOTIFYMETHOD>
                    </GetUserClass>
                </ResponseClass>
            </msg_response>
        </interface_msg>
    </ns2:root>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>';

$doc = new DOMDocument();
$doc->loadXML(getURLContent($url,$id,$msisdn,$provisioning_recipe));
//$doc->loadXML($result_provisioning);

$xpath = new DOMXPath($doc);

foreach ($xpath->query("//ResultCode/text()")  as $package) {
    $resultCode = $package->textContent;
}
if($resultCode == 0 && $resultDesc ="success"){


$doc = new DOMDocument();
$doc->loadXML(getURLContent($url,$xml_get_subscriber_info));

$xpath = new DOMXPath($doc);

foreach ($xpath->query("//PACKAGEID/text()")  as $match1) {
    $PAK_checking = $match1->textContent;
}

$myArrayPak = explode('$',$PAK_checking);
$key_value = array_search($packageid,$myArrayPak);
        if($key_value)
        {
            
        $conf = new RdKafka\Conf();
        $conf->set('metadata.broker.list','192.168.0.16:9092');
        
        $producer = new RdKafka\Producer($conf);
        $topic = $producer->newTopic("successful-request");
        $produce_date =date('Y-m-d H:i:s');
        
        $ar=date_create($myArrayEndDate[$key_value]);
        $final_date = date_format($ar,"Y-m-d H:i:s");
        $toStore="$id;$msisdn;$package_id;1;$final_date";
        echo "PackageID = $myArrayPak[$key_value],End-Date = $final_date\n";
        $topic->produce(RD_KAFKA_PARTITION_UA,"$toStore");
        $producer->poll(0);
        
        for ($flushRetries = 0; $flushRetries < 10; $flushRetries++) {
            $result = $producer->flush(10000);
            if (RD_KAFKA_RESP_ERR_NO_ERROR === $result) {
                break;
            }
        }
        if (RD_KAFKA_RESP_ERR_NO_ERROR !== $result) {
            throw new \RuntimeException('Was unable to flush,messages might be lost!');
        }   


}
}


function getUrlContent($url,$uid,$pckg,$xml_get_subscriber_info){
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch,CURLOPT_TIMEOUT,CURLOPT_POSTFIELDS,$xml_get_subscriber_info);
$data = curl_exec($ch);
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
//return ($httpcode>=200 && $httpcode<300) ? $data : false;
if($httpcode!= 200)
{
    $conf = new RdKafka\Conf();
        $conf->set('metadata.broker.list','192.168.0.17:9092');
        
        $producer = new RdKafka\Producer($conf);
        $topic = $producer->newTopic("failed-request");
        $produce_date =date('Y-m-d H:i:s');
        
        $toStore="$uid;$msisdn;$pckg;$produce_date";
        $topic->produce(RD_KAFKA_PARTITION_UA,messages might be lost!');
        }   
}
else
{
   return $data;
}

}



}


// run all workers
Worker::runAll();
?>

现在,当我将线程增加到800时,问题开始了:-

Notice: Undefined variable: PAK in test.php.php on line 77
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 69

Warning: DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 69
PHP Notice:  Undefined variable: PAK in test.php.php on line 77

Notice: Undefined variable: PAK in test.php.php on line 77
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166

Warning: DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166
PHP Notice:  Undefined variable: resultCode in test.php.php on line 182

Notice: Undefined variable: resultCode in test.php.php on line 182
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 185

Warning: DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 185
PHP Notice:  Undefined variable: PAK_checking in test.php.php on line 197

Notice: Undefined variable: PAK_checking in test.php.php on line 197
PHP Notice:  Undefined variable: psetdatelist in test.php.php on line 198

Notice: Undefined variable: psetdatelist in test.php.php on line 198
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166

Warning: DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166
PHP Notice:  Undefined variable: resultCode in test.php.php on line 182

Notice: Undefined variable: resultCode in test.php.php on line 182
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166

Warning: DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166
PHP Notice:  Undefined variable: resultCode in test.php.php on line 182

Notice: Undefined variable: resultCode in test.php.php on line 182
PHP Warning:  DOMDocument::loadXML(): Empty string supplied as input in test.php.php on line 166

我检查了一下,当我增加工作人员人数时,CURL XML似乎为空。 但是当它是400个http_worker时,根本没有问题。

我在VM上的8核心CPU和16GB RAM上运行。 我的目标是要处理来自北向的尽可能多的请求,并检查具有最低300 TPS的南向。

处理流程如下:-

客户端-> Main.php->向南检查->生成Kafka主题

问题:当我从400个线程增加到800个线程时,我遇到的问题是我的卷曲响应始终为空。

我是否可以利用任何方法发送最低300 tps的数据并进行XML解析而没有任何问题?还是对我有任何改善流程的建议?

解决方法

我发现OS Unix在处理200-300 tps以上的多个请求时有局限性。

我找到了另一个使用guzzleHTTP的替代方法,它对我有帮助。 它帮助我达到了600 tps +的速度,并且交易延迟为2秒。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-