Skip to content

Commit

Permalink
fix data_gen (#375)
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos authored Jul 18, 2023
1 parent fdfcc54 commit e66d26b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/ylt/coro_io/io_context_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <thread>
#include <type_traits>
#include <vector>
#include <ylt/easylog.hpp>

namespace coro_io {

Expand Down Expand Up @@ -96,6 +97,7 @@ class io_context_pool {
pool_size = 1; // set default value as 1
}

easylog::logger<>::instance();
for (std::size_t i = 0; i < pool_size; ++i) {
io_context_ptr io_context(new asio::io_context);
work_ptr work(new asio::io_context::work(*io_context));
Expand Down
15 changes: 14 additions & 1 deletion src/coro_rpc/benchmark/data_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <chrono>
#include <cstdlib>
#include <filesystem>
#include <future>
#include <thread>
#include <ylt/coro_rpc/coro_rpc_client.hpp>
#include <ylt/coro_rpc/coro_rpc_server.hpp>
Expand All @@ -28,13 +29,20 @@ using namespace std::chrono_literals;
int main() {
using namespace coro_rpc;
coro_rpc::coro_rpc_server server(std::thread::hardware_concurrency(), 0);

register_handlers(server);
auto started = server.async_start();
if (!started) {
ELOGV(ERROR, "server started failed");
return -1;
}

std::promise<void> promise;
std::thread thd([&promise] {
promise.set_value();
pool.run();
});
promise.get_future().wait();

coro_rpc_client client;

syncAwait(client.connect("localhost", std::to_string(server.port())));
Expand Down Expand Up @@ -105,5 +113,10 @@ int main() {

server.stop();

started->wait();

pool.stop();
thd.join();

return 0;
};
7 changes: 5 additions & 2 deletions src/coro_rpc/benchmark/server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

#include "api/rpc_functions.hpp"

inline int start_server(coro_rpc::coro_rpc_server& server) {
using namespace coro_rpc;
inline void register_handlers(coro_rpc::coro_rpc_server& server) {
server.register_handler<
echo_4B, echo_100B, echo_500B, echo_1KB, echo_5KB, echo_10KB, async_io,
block_io, heavy_calculate, long_tail_async_io, long_tail_block_io,
Expand All @@ -29,6 +28,10 @@ inline int start_server(coro_rpc::coro_rpc_server& server) {
server.register_handler<
many_argument<int, int, int, int, int, int, int, int, int, int, double,
double, double, double, double, double>>();
}

inline int start_server(coro_rpc::coro_rpc_server& server) {
register_handlers(server);
std::cout << "hardware_concurrency=" << std::thread::hardware_concurrency()
<< std::endl;
try {
Expand Down

0 comments on commit e66d26b

Please sign in to comment.