From 8cf8705d076e1e1c71abc2469d12c0e3e3954cec Mon Sep 17 00:00:00 2001 From: Klein Hu Date: Tue, 30 Apr 2019 10:05:53 -0700 Subject: [PATCH] Support up to 10MiB http request (#61) * Changes minimum request size to 10MB to support all models in ONNX Model Zoo --- onnxruntime/server/http/core/session.cc | 11 ++++++----- onnxruntime/server/http/core/session.h | 3 +-- .../test/server/integration_tests/model_zoo_tests.py | 2 +- .../test/server/integration_tests/test_util.py | 6 +++--- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/onnxruntime/server/http/core/session.cc b/onnxruntime/server/http/core/session.cc index e7463ade65226..1e20fb8bcc83e 100644 --- a/onnxruntime/server/http/core/session.cc +++ b/onnxruntime/server/http/core/session.cc @@ -15,11 +15,12 @@ HttpSession::HttpSession(const Routes& routes, tcp::socket socket) } void HttpSession::DoRead() { - // Make the request empty before reading, - // otherwise the operation behavior is undefined. - req_ = {}; + req_.emplace(); - http::async_read(socket_, buffer_, req_, + // TODO: make the max request size configable. + req_->body_limit(10 * 1024 * 1024); // Max request size: 10 MiB + + http::async_read(socket_, buffer_, *req_, net::bind_executor( strand_, std::bind( @@ -43,7 +44,7 @@ void HttpSession::OnRead(beast::error_code ec, std::size_t bytes_transferred) { } // Send the response - HandleRequest(std::move(req_)); + HandleRequest(req_->release()); } void HttpSession::OnWrite(beast::error_code ec, std::size_t bytes_transferred, bool close) { diff --git a/onnxruntime/server/http/core/session.h b/onnxruntime/server/http/core/session.h index c1c8dd5f3c0a6..388b3069cf8fd 100644 --- a/onnxruntime/server/http/core/session.h +++ b/onnxruntime/server/http/core/session.h @@ -39,7 +39,7 @@ class HttpSession : public std::enable_shared_from_this { tcp::socket socket_; net::strand strand_; beast::flat_buffer buffer_; - http::request req_; + boost::optional> req_; std::shared_ptr res_{nullptr}; // Writes the message asynchronously back to the socket @@ -76,4 +76,3 @@ class HttpSession : public std::enable_shared_from_this { } // namespace server } // namespace onnxruntime - diff --git a/onnxruntime/test/server/integration_tests/model_zoo_tests.py b/onnxruntime/test/server/integration_tests/model_zoo_tests.py index c47a9c50b030d..b752ab9a2af54 100644 --- a/onnxruntime/test/server/integration_tests/model_zoo_tests.py +++ b/onnxruntime/test/server/integration_tests/model_zoo_tests.py @@ -20,7 +20,7 @@ class ModelZooTests(unittest.TestCase): model_zoo_model_path = '' # Required model_zoo_test_data_path = '' # Required supported_opsets = ['opset_7', 'opset_8', 'opset_9'] - skipped_models = ['tiny_yolov2'] + skipped_models = [] def test_models_from_model_zoo(self): json_request_headers = { diff --git a/onnxruntime/test/server/integration_tests/test_util.py b/onnxruntime/test/server/integration_tests/test_util.py index 4b142f3e6dd3f..2cee63bbd5890 100644 --- a/onnxruntime/test/server/integration_tests/test_util.py +++ b/onnxruntime/test/server/integration_tests/test_util.py @@ -55,9 +55,9 @@ def decode_base64_string(s, count_and_type): return r -def compare_floats(a, b, rel_tol=0.0001): - if not math.isclose(a, b, rel_tol=rel_tol): - test_log('Not match with relative tolerance {0}: {1} and {2}'.format(rel_tol, a, b)) +def compare_floats(a, b, rel_tol=0.0001, abs_tol=0.0001): + if not math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol): + test_log('Not match with relative tolerance {0} and absolute tolerance {1}: {2} and {3}'.format(rel_tol, abs_tol, a, b)) return False return True