当前位置: 首页 > 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;…...

基于算法竞赛的c++编程(28)结构体的进阶应用

结构体的嵌套与复杂数据组织 在C中&#xff0c;结构体可以嵌套使用&#xff0c;形成更复杂的数据结构。例如&#xff0c;可以通过嵌套结构体描述多层级数据关系&#xff1a; struct Address {string city;string street;int zipCode; };struct Employee {string name;int id;…...

智慧医疗能源事业线深度画像分析(上)

引言 医疗行业作为现代社会的关键基础设施,其能源消耗与环境影响正日益受到关注。随着全球"双碳"目标的推进和可持续发展理念的深入,智慧医疗能源事业线应运而生,致力于通过创新技术与管理方案,重构医疗领域的能源使用模式。这一事业线融合了能源管理、可持续发…...

Leetcode 3576. Transform Array to All Equal Elements

Leetcode 3576. Transform Array to All Equal Elements 1. 解题思路2. 代码实现 题目链接&#xff1a;3576. Transform Array to All Equal Elements 1. 解题思路 这一题思路上就是分别考察一下是否能将其转化为全1或者全-1数组即可。 至于每一种情况是否可以达到&#xf…...

AI编程--插件对比分析:CodeRider、GitHub Copilot及其他

AI编程插件对比分析&#xff1a;CodeRider、GitHub Copilot及其他 随着人工智能技术的快速发展&#xff0c;AI编程插件已成为提升开发者生产力的重要工具。CodeRider和GitHub Copilot作为市场上的领先者&#xff0c;分别以其独特的特性和生态系统吸引了大量开发者。本文将从功…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据

微软PowerBI考试 PL300-在 Power BI 中清理、转换和加载数据 Power Query 具有大量专门帮助您清理和准备数据以供分析的功能。 您将了解如何简化复杂模型、更改数据类型、重命名对象和透视数据。 您还将了解如何分析列&#xff0c;以便知晓哪些列包含有价值的数据&#xff0c;…...

BLEU评分:机器翻译质量评估的黄金标准

BLEU评分&#xff1a;机器翻译质量评估的黄金标准 1. 引言 在自然语言处理(NLP)领域&#xff0c;衡量一个机器翻译模型的性能至关重要。BLEU (Bilingual Evaluation Understudy) 作为一种自动化评估指标&#xff0c;自2002年由IBM的Kishore Papineni等人提出以来&#xff0c;…...

【FTP】ftp文件传输会丢包吗?批量几百个文件传输,有一些文件没有传输完整,如何解决?

FTP&#xff08;File Transfer Protocol&#xff09;本身是一个基于 TCP 的协议&#xff0c;理论上不会丢包。但 FTP 文件传输过程中仍可能出现文件不完整、丢失或损坏的情况&#xff0c;主要原因包括&#xff1a; ✅ 一、FTP传输可能“丢包”或文件不完整的原因 原因描述网络…...

Appium下载安装配置保姆教程(图文详解)

目录 一、Appium软件介绍 1.特点 2.工作原理 3.应用场景 二、环境准备 安装 Node.js 安装 Appium 安装 JDK 安装 Android SDK 安装Python及依赖包 三、安装教程 1.Node.js安装 1.1.下载Node 1.2.安装程序 1.3.配置npm仓储和缓存 1.4. 配置环境 1.5.测试Node.j…...

工厂方法模式和抽象工厂方法模式的battle

1.案例直接上手 在这个案例里面&#xff0c;我们会实现这个普通的工厂方法&#xff0c;并且对比这个普通工厂方法和我们直接创建对象的差别在哪里&#xff0c;为什么需要一个工厂&#xff1a; 下面的这个是我们的这个案例里面涉及到的接口和对应的实现类&#xff1a; 两个发…...