It takes about one second of time to read a request through async_read with large serialized jpeg pictures (about 2-3 MB). The reading works correctly and quickly on images up to 1 MB, but then hard delays begin, possibly related to the allocation of request_parser
boost::optional<boost::beast::http::request_parser<boost::beast::http::string_body>> request_pars_;
boost::beast::http::request<boost::beast::http::string_body> request_;
boost::beast::http::responce<boost::beast::http::string_body> resounce_;
void Connection::read() {
request_pars_.emplace();
request_pars_->body_limit(10485760); // 10 MB
boost::beast::http::async_read(socket_, buffer_, request_pars_,
[self = shared_from_this()](boost::system::error_code err, size_t bytes_transferred) {
boost::ignore_unused(bytes_transferred);
self->readHandle(err);
});
}
void Connection::readHandle(boost::system::error_code err) {
request_ = request_pars_->release();
response_process_.do_request();
response_ = response_process_.get_response();
writeResponse();
}
void Connection::writeResponse() {
response_.set("keep-alive", true);
boost::beast::http::async_write(socket_, response_,
[self = shared_from_this()](boost::system::error_code err, size_t bytes_transferred) {
if (err) {
self->socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_send, err);
} else {
self->read();
}
});
}
A very large amount of time passes from the call of the Connection::read function to the Connection::readHandle function