diff options
author | JellyBrick <shlee1503@naver.com> | 2018-06-02 03:14:53 +0900 |
---|---|---|
committer | JellyBrick <shlee1503@naver.com> | 2018-06-02 03:14:53 +0900 |
commit | 24071e4aa02a2720c0047e877b8c6faf2a4c05d5 (patch) | |
tree | 83b5bc5fb77be49ed4abf0f827c3b6f83f03daac | |
parent | fa662a813bc36db87a83e2eae02f598f4342240f (diff) |
Add optimization option
-rw-r--r-- | README.md | 16 | ||||
-rw-r--r-- | src/net/HttpClient.cpp | 24 |
2 files changed, 40 insertions, 0 deletions
@@ -52,6 +52,22 @@ sudo make install g++ telegram_bot.cpp -o telegram_bot --std=c++11 -I/usr/local/include -lTgBot -lboost_system -lssl -lcrypto -lpthread ``` +### Bot compile define + +#### With CMake +``` +add_definitions(-DTGBOT_DISABLE_NAGLES_ALGORITHM) # Disable 'Nagle's algorithm' +add_definitions(-DTGBOT_CHANGE_SOCKET_BUFFER_SIZE) # Socket Buffer Size Expansion +add_definitions(-DTGBOT_CHANGE_READ_BUFFER_SIZE) # Read Buffer Size Expansion +``` + +### Without CMake +``` +-DTGBOT_DISABLE_NAGLES_ALGORITHM +-DTGBOT_CHANGE_SOCKET_BUFFER_SIZE +-DTGBOT_CHANGE_READ_BUFFER_SIZE +``` + ### Also You can use Docker to build and run your bot. Set the base image of your's Dockerfile to [reo7sp/tgbot-cpp](https://hub.docker.com/r/reo7sp/tgbot-cpp/). diff --git a/src/net/HttpClient.cpp b/src/net/HttpClient.cpp index f7f4a6b..340eb1e 100644 --- a/src/net/HttpClient.cpp +++ b/src/net/HttpClient.cpp @@ -45,6 +45,20 @@ string HttpClient::makeRequest(const Url& url, const vector<HttpReqArg>& args) { connect(socket.lowest_layer(), resolver.resolve(query)); + #ifdef TGBOT_DISABLE_NAGLES_ALGORITHM + socket.lowest_layer().set_option(tcp::no_delay(true)); + #endif //TGBOT_DISABLE_NAGLES_ALGORITHM + + #ifdef TGBOT_CHANGE_SOCKET_BUFFER_SIZE + #if _WIN64 || __amd64__ || __x86_64__ || __MINGW64__ || __aarch64__ || __powerpc64__ + socket.lowest_layer().set_option(socket_base::send_buffer_size(65536)); + socket.lowest_layer().set_option(socket_base::receive_buffer_size(65536)); + #else //for 32-bit + socket.lowest_layer().set_option(socket_base::send_buffer_size(32768)); + socket.lowest_layer().set_option(socket_base::receive_buffer_size(32768)); + #endif //Processor architecture + #endif //TGBOT_CHANGE_SOCKET_BUFFER_SIZE + socket.set_verify_mode(ssl::verify_none); socket.set_verify_callback(ssl::rfc2818_verification(url.host)); socket.handshake(ssl::stream<tcp::socket>::client); @@ -53,7 +67,17 @@ string HttpClient::makeRequest(const Url& url, const vector<HttpReqArg>& args) { write(socket, buffer(requestText.c_str(), requestText.length())); string response; + + #ifdef TGBOT_CHANGE_READ_BUFFER_SIZE + #if _WIN64 || __amd64__ || __x86_64__ || __MINGW64__ || __aarch64__ || __powerpc64__ + char buff[65536]; + #else //for 32-bit + char buff[32768]; + #endif //Processor architecture + #else char buff[1024]; + #endif //TGBOT_CHANGE_READ_BUFFER_SIZE + boost::system::error_code error; while (!error) { size_t bytes = read(socket, buffer(buff), error); |