Add a client program to test server's concurrency performance.

master
Chunting Gu 6 years ago
parent cfbd1a278f
commit f023fb830c

@ -0,0 +1,50 @@
#include <iostream>
#include <string>
#include <thread>
#include <vector>
#include "webcc/client_session.h"
#include "webcc/logger.h"
// CS Server:
// $ concurrency_test 10 http://localhost:55555/patient/query?global_search=ivory&count=200&offset=0&sort_item=birth_date&sort_order=asc
// GitHub:
// $ concurrency_test 10 https://api.github.com/public/events
int main(int argc, const char* argv[]) {
if (argc < 3) {
std::cerr << "Usage: concurrency_test <workers> <url>" << std::endl;
return 1;
}
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE_FILE_OVERWRITE);
int workers = std::atoi(argv[1]);
std::string url = argv[2];
LOG_USER("Workers: %d", workers);
LOG_USER("URL: %s", url.c_str());
std::vector<std::thread> threads;
for (int i = 0; i < workers; ++i) {
threads.emplace_back([&url]() {
webcc::ClientSession session;
session.set_timeout(180);
try {
LOG_USER("Start");
session.Get(url);
LOG_USER("End");
} catch (const webcc::Error& error) {
LOG_ERRO("Error: %s", error.message().c_str());
}
});
}
for (int i = 0; i < workers; ++i) {
threads[i].join();
}
return 0;
}

@ -0,0 +1,58 @@
The client creates 10 threads to send the query request at the same time.
List GitHub public events:
GET https://api.github.com/events
1 thread
Round 1:
2019-07-05 09:42:23.048, USER, main, concurrency_test.cc, 31, URL: http://10.196.98.32:55555
2019-07-05 09:42:23.063, USER, main, concurrency_test.cc, 32, Workers: 1
2019-07-05 09:42:23.063, USER, 15396, concurrency_test.cc, 55, Start
2019-07-05 09:42:25.893, USER, 15396, concurrency_test.cc, 60, End
Round 2:
2019-07-05 09:42:52.136, USER, main, concurrency_test.cc, 31, URL: http://10.196.98.32:55555
2019-07-05 09:42:52.136, USER, main, concurrency_test.cc, 32, Workers: 1
2019-07-05 09:42:52.136, USER, 5376, concurrency_test.cc, 55, Start
2019-07-05 09:42:54.441, USER, 5376, concurrency_test.cc, 60, End
Round 3:
2019-07-05 09:43:10.768, USER, main, concurrency_test.cc, 31, URL: http://10.196.98.32:55555
2019-07-05 09:43:10.783, USER, main, concurrency_test.cc, 32, Workers: 1
2019-07-05 09:43:10.783, USER, 14620, concurrency_test.cc, 55, Start
2019-07-05 09:43:13.405, USER, 14620, concurrency_test.cc, 60, End
=> 2.5s
10 threads:
2019-07-05 09:44:04.016, USER, main, concurrency_test.cc, 31, URL: http://10.196.98.32:55555
2019-07-05 09:44:04.032, USER, main, concurrency_test.cc, 32, Workers: 10
2019-07-05 09:44:04.032, USER, 17348, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 10600, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 4852, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 9480, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 10952, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 6452, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 13060, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 14840, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 4464, concurrency_test.cc, 55, Start
2019-07-05 09:44:04.032, USER, 11304, concurrency_test.cc, 55, Start
2019-07-05 09:44:06.739, USER, 10952, concurrency_test.cc, 60, End
2019-07-05 09:44:06.823, USER, 9480, concurrency_test.cc, 60, End
2019-07-05 09:44:06.839, USER, 4464, concurrency_test.cc, 60, End
2019-07-05 09:44:06.861, USER, 14840, concurrency_test.cc, 60, End
2019-07-05 09:44:06.908, USER, 11304, concurrency_test.cc, 60, End
2019-07-05 09:44:06.908, USER, 13060, concurrency_test.cc, 60, End
2019-07-05 09:44:06.908, USER, 4852, concurrency_test.cc, 60, End
2019-07-05 09:44:06.923, USER, 10600, concurrency_test.cc, 60, End
2019-07-05 09:44:06.977, USER, 17348, concurrency_test.cc, 60, End
2019-07-05 09:44:07.193, USER, 6452, concurrency_test.cc, 60, End
=> 2.5s (still)
Loading…
Cancel
Save