当前位置: 首页 > news >正文

libhv http client vs cpr

libhv http client 和 cpr 的性能对比

libhv

  • test code
static void test_http_async(HttpClient* cli, int seq, int* resp_cnt) 
{auto req = std::make_shared<HttpRequest>();req->method = HTTP_GET;req->url = "www.baidu.com";req->timeout = 10;cli->sendAsync(req, [seq, resp_cnt](const HttpResponsePtr& resp) {std::string path = "async-result-" + std::to_string(seq) + ".log";std::ofstream fout(path.c_str());fout << "test_http_async_client response thread" << std::endl;fout << "tid=" << hv_gettid() << std::endl;if (resp == NULL) {fout << "request failed!" << std::endl;} else {fout << resp->status_code << "\t" <<  resp->status_message() << std::endl;// fout << resp->body << std::endl;}*resp_cnt += 1;});
}static void test_http_sync(HttpClient* cli, int seq) 
{HttpRequest req;req.method = HTTP_POST;req.url = "www.baidu.com";req.timeout = 10;HttpResponse resp;int ret = cli->send(&req, &resp);std::string path = "sync-result-" + std::to_string(seq) + ".log";std::ofstream fout(path.c_str());fout << "test_http_sync_client response thread" << std::endl;if (ret != 0) {fout << "request failed!" << std::endl;}else {fout << resp.status_code << "\t" <<  resp.status_message() << std::endl;// fout << resp->body << std::endl;}
}int main(int argc, char* argv[]) {int req_cnt = 0;if (argc > 1) req_cnt = atoi(argv[1]);if (req_cnt == 0) req_cnt = 1;HttpClient sync_client;HttpClient async_client;int resp_cnt = 0;long long beg = gettimeofday_ms();printf("test_http_async_client request thread tid=%ld\n", hv_gettid());for (int i = 0; i < req_cnt; ++i) {test_http_async(&async_client, i, &resp_cnt);}// demo wait async finishedwhile (resp_cnt < req_cnt) hv_delay(10);long long used = gettimeofday_ms() - beg;std::cout << "async finished: " << used << std::endl;beg = gettimeofday_ms();printf("test_http_sync_client request thread tid=%ld\n", hv_gettid());for (int i = 0; i < req_cnt; ++i) {test_http_sync(&async_client, i);}used = gettimeofday_ms() - beg;std::cout << "sync finished: " << used << std::endl;return 0;
}
  • result
test_http_async_client request thread tid=104820
async finished: 3249ms
test_http_sync_client request thread tid=104820
sync finished: 80398ms[wei@localmachine /home/wei/myworks/libhv]
$cat async-result-*.log | grep "tid=" | sort | uniq -c1000 tid=104823

cpr

  • test code

void test_http_async(int seq, int *resp_cnt, vector<std::shared_future<string> >& futures)
{auto callback = [seq, resp_cnt](cpr::Response r) {std::string path = "async-result-" + std::to_string(seq) + ".log";std::ofstream fout(path.c_str());fout << "test async response thread" << std::endl;fout << "tid=" << std::this_thread::get_id() << std::endl;fout << r.status_code << "\t" <<  r.status_line << std::endl;if (r.status_code != 200){fout << "error:" << r.error.message << endl;}// else// {//     fout << r.text << std::endl;// }*resp_cnt += 1;return r.text;};string url = "http://www.baidu.com";int timeout = 10 * 1000;futures[seq] = cpr::GetCallback(callback, cpr::Url{url}, cpr::Timeout{timeout});
}void test_http_sync(int seq)
{string url = "http://www.baidu.com";int timeout = 10 * 1000;auto r = cpr::Get(cpr::Url{url}, cpr::Timeout{timeout});std::string path = "sync-result-" + std::to_string(seq) + ".log";std::ofstream fout(path.c_str());fout << "test sync response thread" << std::endl;fout << "tid=" << std::this_thread::get_id() << std::endl;fout << r.status_code << "\t" <<  r.status_line << std::endl;if (r.status_code != 200){fout << "error:" << r.error.message << endl;}// else// {//     fout << r.text << std::endl;// }
}void CprRequestTest::AsyncSyncRequestTest()
{int req_cnt = 1000;int resp_cnt = 0;vector<std::shared_future<string>> cprfutures(req_cnt);cprfutures.reserve(1000);int64_t beg = Timer::GetCurrentTimeInMilliSeconds();cout << "test async request thread tid=" << std::this_thread::get_id() << endl;;for (int i = 0; i < req_cnt; ++i) {test_http_async(i, &resp_cnt, cprfutures);// cprfutures.emplace_back(f);}// demo wait async finishedwhile (resp_cnt < req_cnt) usleep(10 * 1000);int64_t used = Timer::GetCurrentTimeInMilliSeconds() - beg;std::cout << "async finished: " << used << "ms" << std::endl;beg = Timer::GetCurrentTimeInMilliSeconds();cout << "test sync request thread tid=" << std::this_thread::get_id() << endl;;for (int i = 0; i < req_cnt; ++i) {test_http_sync(i);}used = Timer::GetCurrentTimeInMilliSeconds() - beg;std::cout << "sync finished: " << used << "ms" << std::endl;
}
  • result
test async request thread tid=140052864329472
async finished: 554ms
test sync request thread tid=140052864329472
sync finished: 32382ms[wei@localmachine /home/wei/myworks/cpr]
cat async-result-*.log | grep "tid=" | sort | uniq -c | wc -l
1000

  • 机器
processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 63
model name      : Intel(R) Xeon(R) CPU E5-2640 v3 @ 2.60GHz
stepping        : 2
microcode       : 0x3a
cpu MHz         : 2600.000
cache size      : 20480 KB
physical id     : 0
siblings        : 16
core id         : 0
cpu cores       : 16
apicid          : 10
initial apicid  : 10
fpu             : yes
fpu_exception   : yes
cpuid level     : 15
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm arat epb pln pts dtherm tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm xsaveopt cqm_llc cqm_occup_llc
bogomips        : 5187.90
clflush size    : 64
cache_alignment : 64
address sizes   : 46 bits physical, 48 bits virtual
power management:[wei@localmachine /home/wei]
cat /proc/cpuinfo | grep processor | wc -l
16

相关文章:

libhv http client vs cpr

libhv http client 和 cpr 的性能对比 libhv test code static void test_http_async(HttpClient* cli, int seq, int* resp_cnt) {auto req std::make_shared<HttpRequest>();req->method HTTP_GET;req->url "www.baidu.com";req->timeout 1…...

CTFHub-Web-文件上传

CTFHub-Web-文件上传-WP 一、无验证 1.编写一段PHP木马脚本 2.将编写好的木马进行上传 3.显示上传成功了 4.使用文件上传工具进行尝试 5.连接成功进入文件管理 6.上翻目录找到flag文件 7.打开文件查看flag 二、前端验证 1.制作payload进行上传发现不允许这种类型的文件上传 …...

笔记2:cifar10数据集获取及pytorch批量处理

&#xff08;1&#xff09;cifar10数据集预处理 CIFAR-10是一个广泛使用的图像数据集&#xff0c;它由10个类别的共60000张32x32彩色图像组成&#xff0c;每个类别有6000张图像。 CIFAR-10官网 以下为CIFAR-10数据集data_batch_*表示训练集数据&#xff0c;test_batch表示测试…...

FSD自动驾驶泛谈

特斯拉的FSD&#xff08;Full-Self Driving&#xff0c;全自动驾驶&#xff09;系统是特斯拉公司研发的一套完全自动驾驶系统。旨在最终实现车辆在多种驾驶环境下无需人类干预的自动驾驶能力。以下是对FSD系统的详细探讨&#xff1a; 系统概述 FSD是特斯拉的自动驾驶技术&…...

golang获取变量动态类型

类型断言&#xff1a;data.(Type) 类型断言是最常用的获取变量动态类型的方法之一。允许在运行时将接口值转换为其具体类型。 data 是一个接口类型的变量。 Type 是一个具体的类型。 这个表达式的含义是&#xff0c;如果 data 的底层值是 Type 类型&#xff0c;那么 value 将接…...

外企接受大龄程序员吗?

本人知乎账号同公众号&#xff1a;老胡聊Java&#xff0c;欢迎留言并咨询 亲身体会外企经历所见所闻&#xff0c;外企能接受大龄程序员。 1 大概是10年的时候&#xff0c;进一家知名外企&#xff0c;和我一起进的一位manager&#xff0c;后来听下来&#xff0c;年龄35&#xf…...

【DevOps】掌控云端:Google Cloud SDK 快速上手

一、Google Cloud SDK Google Cloud SDK (Software Development Kit) 是一组工具,包括 gcloud、gsutil 和 bq,用于通过命令行或自动化脚本访问和管理 Google Cloud 资源和服务。以下是 Cloud SDK 的详细介绍: 1、gcloud 命令行工具 gcloud 是 Cloud SDK 的核心组件,用于管理 …...

【Unity 踩坑系列】配置VScode环境Downloading the.NET Runtime Failed to download.NET 7.0.9installation timed out

1.问题描述 在最近使用Unity配置VScode开发环境时&#xff0c;总会出现以下的情况。(很多朋友其实本地已经自己安装好了.net环境 PS:可能各种版本.net 6.0 - .net 8.0都试过安装了 但就是会自动下载最新版本的.net ) Downloading the .NET Runtime. Downloading .NET versio…...

深入了解 NumPy:深度学习中的数学运算利器

文章目录 1. 导入NumPy2. 创建NumPy数组3. 数组的算术运算4. N维数组4.1 创建和操作多维数组4.2 高维数组 5. NumPy的广播功能5.1 基本广播示例5.2 更复杂的广播示例 6. 访问数组元素6.1 基于索引的访问6.2 遍历数组6.3 基于条件的访问6.4 高级索引6.5 性能考虑 在深度学习和数…...

鸿蒙开发接口Ability框架:【@ohos.ability.particleAbility (particleAbility模块)】

particleAbility模块 particleAbility模块提供了Service类型Ability的能力&#xff0c;包括启动、停止指定的particleAbility&#xff0c;获取dataAbilityHelper&#xff0c;连接、断开当前Ability与指定ServiceAbility等。 说明&#xff1a; 本模块首批接口从API version 7开…...

Flutter笔记:Widgets Easier组件库(8)使用图片

Flutter笔记 Widgets Easier组件库&#xff08;8&#xff09;&#xff1a;使用图片 - 文章信息 - Author: 李俊才 (jcLee95) Visit me at CSDN: https://jclee95.blog.csdn.netMy WebSite&#xff1a;http://thispage.tech/Email: 291148484163.com. Shenzhen ChinaAddress o…...

商务分析方法与工具(五):Python的趣味快捷-文件和文件夹操作自动化

Tips&#xff1a;"分享是快乐的源泉&#x1f4a7;&#xff0c;在我的博客里&#xff0c;不仅有知识的海洋&#x1f30a;&#xff0c;还有满满的正能量加持&#x1f4aa;&#xff0c;快来和我一起分享这份快乐吧&#x1f60a;&#xff01; 喜欢我的博客的话&#xff0c;记得…...

codeforce#938 (div3) 题解

C. Inhabitant of the Deep Sea 数组第一个元素减一下&#xff0c;最后一个元素减一下&#xff0c;一共能减k次&#xff0c;问有多少元素能减到0.细节模拟我是傻逼&#xff0c;有问题建议直接看tc面像tc编程 #include <iostream> #include <string.h> #include &…...

【Docker】如何注册Hub账号并上传镜像到Hub仓库

一、创建Hub账户 浏览器访问&#xff1a;hub.docker.com 点击【Sign up】注册账号 输入【邮箱】【用户名】【密码】 ps&#xff1a;用户名要有字母数字&#xff1b;订阅不用勾选 点击【Sign up】注册即可 点击【Sign in】登录账号 输入【邮箱】【密码】 点击【Continue】登录 二…...

[初阶数据结构】单链表

前言 &#x1f4da;作者简介&#xff1a;爱编程的小马&#xff0c;正在学习C/C&#xff0c;Linux及MySQL。 &#x1f4da;本文收录于初阶数据结构系列&#xff0c;本专栏主要是针对时间、空间复杂度&#xff0c;顺序表和链表、栈和队列、二叉树以及各类排序算法&#xff0c;持…...

项目使用git开发流程

第一步 项目初期&#xff1a;领导负责的工作 01 创建仓库&#xff1a;在码云上面创建仓库地址&#xff0c;创建完成后点击初始化README&#xff1a;郝陶涛/vue-tea 02 领导在桌面上将代码克隆下来&#xff1a;将代码克隆下来之后&#xff0c;切换到代码内部&#xff0c;使用g…...

Day 28 MySQL的数据备份与恢复

数据备份及恢复 1.概述 ​ 所有备份数据都应放在非数据库本地&#xff0c;而且建议有多份副本 备份&#xff1a; 能够防止由于机械故障以及人为误操作带来的数据丢失&#xff0c;例如将数据库文件保存在了其它地方 冗余&#xff1a; 数据有多份冗余&#xff0c;但不等备份&…...

PackageKit的使用(三)疑问篇

本篇主要是一些疑问归纳&#xff0c;不做具体的函数分析&#xff0c;但是会给出关键点&#xff0c;查看源码就会很清楚了 apt source PackageKit 1. org.freedesktop.PackageKit D-Bus 接口介绍 D-Bus API Reference: PackageKit Reference Manual c库的接口可以看源码。 2.…...

【Linux】17. 进程间通信 --- 管道

1. 什么是进程间通信(进程间通信的目的) 数据传输&#xff1a;一个进程需要将它的数据发送给另一个进程 资源共享&#xff1a;多个进程之间共享同样的资源。 通知事件&#xff1a;一个进程需要向另一个或一组进程发送消息&#xff0c;通知它&#xff08;它们&#xff09;发生了…...

有哪些有效的复习方法可以帮助备考软考?

软考目前仍然是一个以记忆为主、理解为辅的考试。学过软考的朋友可能会感到困惑&#xff0c;因为软考的知识在日常工作中有许多应用场景&#xff0c;需要理解的地方也很多。但为什么我说它是理解为辅呢&#xff1f;因为这些知识点只要记住了&#xff0c;都不难理解&#xff0c;…...

Spring Boot 实现流式响应(兼容 2.7.x)

在实际开发中&#xff0c;我们可能会遇到一些流式数据处理的场景&#xff0c;比如接收来自上游接口的 Server-Sent Events&#xff08;SSE&#xff09; 或 流式 JSON 内容&#xff0c;并将其原样中转给前端页面或客户端。这种情况下&#xff0c;传统的 RestTemplate 缓存机制会…...

三体问题详解

从物理学角度&#xff0c;三体问题之所以不稳定&#xff0c;是因为三个天体在万有引力作用下相互作用&#xff0c;形成一个非线性耦合系统。我们可以从牛顿经典力学出发&#xff0c;列出具体的运动方程&#xff0c;并说明为何这个系统本质上是混沌的&#xff0c;无法得到一般解…...

技术栈RabbitMq的介绍和使用

目录 1. 什么是消息队列&#xff1f;2. 消息队列的优点3. RabbitMQ 消息队列概述4. RabbitMQ 安装5. Exchange 四种类型5.1 direct 精准匹配5.2 fanout 广播5.3 topic 正则匹配 6. RabbitMQ 队列模式6.1 简单队列模式6.2 工作队列模式6.3 发布/订阅模式6.4 路由模式6.5 主题模式…...

springboot整合VUE之在线教育管理系统简介

可以学习到的技能 学会常用技术栈的使用 独立开发项目 学会前端的开发流程 学会后端的开发流程 学会数据库的设计 学会前后端接口调用方式 学会多模块之间的关联 学会数据的处理 适用人群 在校学生&#xff0c;小白用户&#xff0c;想学习知识的 有点基础&#xff0c;想要通过项…...

CRMEB 中 PHP 短信扩展开发:涵盖一号通、阿里云、腾讯云、创蓝

目前已有一号通短信、阿里云短信、腾讯云短信扩展 扩展入口文件 文件目录 crmeb\services\sms\Sms.php 默认驱动类型为&#xff1a;一号通 namespace crmeb\services\sms;use crmeb\basic\BaseManager; use crmeb\services\AccessTokenServeService; use crmeb\services\sms\…...

MySQL 部分重点知识篇

一、数据库对象 1. 主键 定义 &#xff1a;主键是用于唯一标识表中每一行记录的字段或字段组合。它具有唯一性和非空性特点。 作用 &#xff1a;确保数据的完整性&#xff0c;便于数据的查询和管理。 示例 &#xff1a;在学生信息表中&#xff0c;学号可以作为主键&#xff…...

Rust 开发环境搭建

环境搭建 1、开发工具RustRover 或者vs code 2、Cygwin64 安装 https://cygwin.com/install.html 在工具终端执行&#xff1a; rustup toolchain install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu ​ 2、Hello World fn main() { println…...

【堆垛策略】设计方法

堆垛策略的设计是积木堆叠系统的核心&#xff0c;直接影响堆叠的稳定性、效率和容错能力。以下是分层次的堆垛策略设计方法&#xff0c;涵盖基础规则、优化算法和容错机制&#xff1a; 1. 基础堆垛规则 (1) 物理稳定性优先 重心原则&#xff1a; 大尺寸/重量积木在下&#xf…...

在golang中如何将已安装的依赖降级处理,比如:将 go-ansible/v2@v2.2.0 更换为 go-ansible/@v1.1.7

在 Go 项目中降级 go-ansible 从 v2.2.0 到 v1.1.7 具体步骤&#xff1a; 第一步&#xff1a; 修改 go.mod 文件 // 原 v2 版本声明 require github.com/apenella/go-ansible/v2 v2.2.0 替换为&#xff1a; // 改为 v…...

【HarmonyOS 5】鸿蒙中Stage模型与FA模型详解

一、前言 在HarmonyOS 5的应用开发模型中&#xff0c;featureAbility是旧版FA模型&#xff08;Feature Ability&#xff09;的用法&#xff0c;Stage模型已采用全新的应用架构&#xff0c;推荐使用组件化的上下文获取方式&#xff0c;而非依赖featureAbility。 FA大概是API7之…...