提交 e5a480cc 编写于 作者: Y yang li

Fix performance downgrade introduced in version 1.4.2

上级 c0c1366d
......@@ -8,7 +8,7 @@
//#define ASCS_SYNC_DISPATCH //do not open this feature, see below for more details
#define ASCS_DISPATCH_BATCH_MSG
#define ASCS_ENHANCED_STABILITY
#define ASCS_FULL_STATISTIC //full statistic will slightly impact efficiency
//#define ASCS_FULL_STATISTIC //full statistic will slightly impact efficiency
#define ASCS_USE_STEADY_TIMER
#define ASCS_ALIGNED_TIMER
#define ASCS_AVOID_AUTO_STOP_SERVICE
......
......@@ -488,6 +488,14 @@ size_t get_size_in_byte(const _Can& __can)
return size_in_byte;
}
template<typename _Can>
size_t get_size_in_byte(const _Can& __can, size_t& size)
{
auto size_in_byte = size = 0;
do_something_to_all(__can, [&size_in_byte, &size](typename _Can::const_reference item) {size_in_byte += item.size(); ++size;});
return size_in_byte;
}
//member functions, used to do something to any member container(except map and multimap) optionally with any member mutex
#define DO_SOMETHING_TO_ALL_MUTEX(CAN, MUTEX) DO_SOMETHING_TO_ALL_MUTEX_NAME(do_something_to_all, CAN, MUTEX)
#define DO_SOMETHING_TO_ALL(CAN) DO_SOMETHING_TO_ALL_NAME(do_something_to_all, CAN)
......
......@@ -370,8 +370,9 @@ protected:
bool handle_msg()
{
auto size_in_byte = ascs::get_size_in_byte(temp_msg_can);
stat.recv_msg_sum += temp_msg_can.size(); //this can have linear complexity in old gcc or Cygwin and Mingw64, please note.
size_t size = 0;
auto size_in_byte = ascs::get_size_in_byte(temp_msg_can, size);
stat.recv_msg_sum += size;
stat.recv_byte_sum += size_in_byte;
#ifdef ASCS_SYNC_RECV
std::unique_lock<std::mutex> lock(sync_recv_mutex);
......
......@@ -300,18 +300,16 @@ private:
#else
send_msg_buffer.move_items_out(asio::detail::default_max_transfer_size, last_send_msg);
#endif
std::vector<asio::const_buffer> bufs;
bufs.reserve(last_send_msg.size());
for (auto iter = std::begin(last_send_msg); iter != std::end(last_send_msg); ++iter)
{
stat.send_delay_sum += end_time - iter->begin_time;
bufs.emplace_back(iter->data(), iter->size());
}
send_bufs.clear(); //this buffer will not be refreshed according to last_send_msg timely
ascs::do_something_to_all(last_send_msg, [this, &end_time](typename super::in_msg& item) {
this->stat.send_delay_sum += end_time - item.begin_time;
this->send_bufs.emplace_back(item.data(), item.size());
});
if ((sending = !bufs.empty()))
if ((sending = !send_bufs.empty()))
{
last_send_msg.front().restart();
asio::async_write(this->next_layer(), bufs, make_strand_handler(strand,
asio::async_write(this->next_layer(), send_bufs, make_strand_handler(strand,
this->make_handler_error_size([this](const asio::error_code& ec, size_t bytes_transferred) {this->send_handler(ec, bytes_transferred);})));
return true;
}
......@@ -327,7 +325,7 @@ private:
stat.send_byte_sum += bytes_transferred;
stat.send_time_sum += statistic::now() - last_send_msg.front().begin_time;
stat.send_msg_sum += last_send_msg.size();
stat.send_msg_sum += send_bufs.size();
#ifdef ASCS_SYNC_SEND
ascs::do_something_to_all(last_send_msg, [](typename super::in_msg& item) {if (item.p) {item.p->set_value(sync_call_result::SUCCESS);}});
#endif
......@@ -391,6 +389,7 @@ private:
std::shared_ptr<i_unpacker<out_msg_type>> unpacker_;
typename super::in_container_type last_send_msg;
std::vector<asio::const_buffer> send_bufs; //just to reduce memory allocation and keep the size of sending items (linear complexity, it's very important)
asio::io_context::strand strand;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册