diff --git a/WORKSPACE b/WORKSPACE index 3190cd2..38b4529 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -67,3 +67,11 @@ http_archive( "https://zlib.net/zlib-1.2.11.tar.gz", ], ) + +http_archive( + name = "com_github_google_benchmark", + strip_prefix = "benchmark-1.6.0", + sha256 = "1f71c72ce08d2c1310011ea6436b31e39ccab8c2db94186d26657d41747c85d6", + url = "https://github.com/google/benchmark/archive/v1.6.0.tar.gz" +) + diff --git a/docs/README.md b/docs/README.md index 2cc0d9d..a671315 100644 --- a/docs/README.md +++ b/docs/README.md @@ -21,12 +21,17 @@ or In our case we want to use Bazel 5.4.0: 5. Verify Installation: `bazel --version` -### Then Install libvert: +### Then Install libvirt: ``` sudo apt-get update sudo apt-get install -y autoconf automake libtool ``` +### Add Google Benchmark: +``` +sudo apt-get install libbenchmark-dev +``` + ## To Build: Under the project root dir: diff --git a/net_http/client/test_client/benchmark/BUILD b/net_http/client/test_client/benchmark/BUILD new file mode 100644 index 0000000..c624656 --- /dev/null +++ b/net_http/client/test_client/benchmark/BUILD @@ -0,0 +1,22 @@ +# Description: net_http/client/test_client/testing + +package(default_visibility = ["//visibility:private"]) + +licenses(["notice"]) + +cc_binary( + name = "evhttp_echo_client", + srcs = ["evhttp_echo_client.cc"], + deps = [ + "//net_http/client/test_client/internal:evhttp_client", + ], +) +cc_binary( + name = "my_benchmark", + srcs = ["evhttp_echo_client_benchmark.cc"], # Replace with your benchmark source file + deps = [ + "@com_github_google_benchmark//:benchmark", + # Add other dependencies your benchmark might have + ], + copts = ["-Iexternal/com_github_google_benchmark/include"], +) diff --git a/net_http/client/test_client/benchmark/evhttp_echo_client_benchmark.cc b/net_http/client/test_client/benchmark/evhttp_echo_client_benchmark.cc new file mode 100644 index 0000000..ba72234 --- /dev/null +++ b/net_http/client/test_client/benchmark/evhttp_echo_client_benchmark.cc @@ -0,0 +1,72 @@ +/* Copyright 2018 Google Inc. All Rights Reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +==============================================================================*/ + +// A benchmark test client to print the response from the evhttp_echo_server +// URI: /print + +#include +#include + +#include "net_http/client/test_client/internal/evhttp_connection.h" + +namespace { + + using net_http::TestClientRequest; + using net_http::TestClientResponse; + using net_http::TestEvHTTPConnection; + + const char* global_url; // Global variable to store the URL + + bool SendRequest(const char* url) { + auto connection = TestEvHTTPConnection::Connect(url); + if (connection == nullptr) { + std::cerr << "Fail to connect to " << url << std::endl; + return false; + } + + TestClientRequest request = {url, "GET", {}, ""}; + TestClientResponse response = {}; + + if (!connection->BlockingSendRequest(request, &response)) { + std::cerr << "Request failed." << std::endl; + return false; + } + + // Suppress output for benchmarking + return true; + } + +} // namespace + +static void BM_SendRequest(benchmark::State& state) { + for (auto _ : state) { + SendRequest(global_url); // Use the global variable + } +} +BENCHMARK(BM_SendRequest); + +int main(int argc, char** argv) { + if (argc < 2) { + std::cerr << "Usage: http-client " << std::endl; + return 1; + } + + global_url = argv[1]; // Set the global URL from argv + + // Run benchmarks + ::benchmark::Initialize(&argc, argv); + ::benchmark::RunSpecifiedBenchmarks(); + return 0; +} diff --git a/net_http/client/test_client/internal/evhttp_connection.h b/net_http/client/test_client/internal/evhttp_connection.h index 2bcd52f..581f78e 100644 --- a/net_http/client/test_client/internal/evhttp_connection.h +++ b/net_http/client/test_client/internal/evhttp_connection.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ +#ifndef NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ +#define NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ #include #include @@ -94,4 +94,4 @@ class TestEvHTTPConnection final : public TestHTTPClientInterface { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ +#endif // NET_HTTP_CLIENT_TEST_CLIENT_INTERNAL_EVHTTP_CONNECTION_H_ diff --git a/net_http/client/test_client/public/httpclient.h b/net_http/client/test_client/public/httpclient.h index a415bce..eb68dda 100644 --- a/net_http/client/test_client/public/httpclient.h +++ b/net_http/client/test_client/public/httpclient.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ -#define THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ +#ifndef NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ +#define NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ #include "absl/memory/memory.h" #include "net_http/client/test_client/internal/evhttp_connection.h" @@ -40,5 +40,5 @@ inline std::unique_ptr CreateEvHTTPConnection( } // namespace net_http -#endif // THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ +#endif // NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_H_ diff --git a/net_http/client/test_client/public/httpclient_interface.h b/net_http/client/test_client/public/httpclient_interface.h index 4f7e597..5beaf63 100644 --- a/net_http/client/test_client/public/httpclient_interface.h +++ b/net_http/client/test_client/public/httpclient_interface.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ -#define THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ +#ifndef NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ +#define NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ #include "net_http/public/response_code_enum.h" #include "net_http/server/public/httpserver_interface.h" @@ -83,4 +83,4 @@ namespace net_http } // namespace net_http -#endif // THIRD_PARTY_TENSORFLOW_SERVING_UTIL_NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ +#endif // NET_HTTP_CLIENT_TEST_CLIENT_PUBLIC_HTTPCLIENT_INTERFACE_H_ diff --git a/net_http/compression/gzip_zlib.h b/net_http/compression/gzip_zlib.h index f158989..d1544a8 100644 --- a/net_http/compression/gzip_zlib.h +++ b/net_http/compression/gzip_zlib.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ +#ifndef NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ +#define NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ #include @@ -340,4 +340,4 @@ namespace net_http } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ +#endif // NET_HTTP_COMPRESSION_GZIP_ZLIB_H_ diff --git a/net_http/internal/fixed_thread_pool.h b/net_http/internal/fixed_thread_pool.h index a85a33e..ae04906 100644 --- a/net_http/internal/fixed_thread_pool.h +++ b/net_http/internal/fixed_thread_pool.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ +#ifndef NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ +#define NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ #include #include @@ -99,4 +99,4 @@ namespace net_http } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ +#endif // NET_HTTP_INTERNAL_FIXED_THREAD_POOL_H_ diff --git a/net_http/internal/net_logging.h b/net_http/internal/net_logging.h index 32f1e12..825597e 100644 --- a/net_http/internal/net_logging.h +++ b/net_http/internal/net_logging.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_NET_LOGGING_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_NET_LOGGING_H_ +#ifndef NET_HTTP_INTERNAL_NET_LOGGING_H_ +#define NET_HTTP_INTERNAL_NET_LOGGING_H_ #include @@ -72,4 +72,4 @@ namespace net_http } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_INTERNAL_NET_LOGGING_H_ +#endif // NET_HTTP_INTERNAL_NET_LOGGING_H_ diff --git a/net_http/public/header_names.h b/net_http/public/header_names.h index 8a244f8..9da47f1 100644 --- a/net_http/public/header_names.h +++ b/net_http/public/header_names.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_HEADER_NAMES_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_HEADER_NAMES_H_ +#ifndef NET_HTTP_PUBLIC_HEADER_NAMES_H_ +#define NET_HTTP_PUBLIC_HEADER_NAMES_H_ namespace net_http { @@ -178,4 +178,4 @@ class HTTPHeaders { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_HEADER_NAMES_H_ +#endif // NET_HTTP_PUBLIC_HEADER_NAMES_H_ diff --git a/net_http/public/response_code_enum.h b/net_http/public/response_code_enum.h index 9b9cc8a..5b77ff3 100644 --- a/net_http/public/response_code_enum.h +++ b/net_http/public/response_code_enum.h @@ -13,8 +13,8 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ +#ifndef NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ +#define NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ namespace net_http { enum class HTTPStatusCode { @@ -105,4 +105,4 @@ enum class HTTPStatusCode { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ +#endif // NET_HTTP_PUBLIC_RESPONSE_CODE_ENUM_H_ diff --git a/net_http/server/internal/evhttp_request.h b/net_http/server/internal/evhttp_request.h index 6f5fcbc..6e4bbac 100644 --- a/net_http/server/internal/evhttp_request.h +++ b/net_http/server/internal/evhttp_request.h @@ -15,8 +15,8 @@ limitations under the License. // libevent based request implementation -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ +#ifndef NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ +#define NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ #include #include @@ -135,4 +135,4 @@ class EvHTTPRequest final : public ServerRequestInterface { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ +#endif // NET_HTTP_SERVER_INTERNAL_EVHTTP_REQUEST_H_ diff --git a/net_http/server/internal/evhttp_server.h b/net_http/server/internal/evhttp_server.h index 482e6b5..2a27914 100644 --- a/net_http/server/internal/evhttp_server.h +++ b/net_http/server/internal/evhttp_server.h @@ -15,8 +15,8 @@ limitations under the License. // libevent based server implementation -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ +#ifndef NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ +#define NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ #include #include @@ -136,4 +136,4 @@ class EvHTTPServer final : public HTTPServerInterface, ServerSupport { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ +#endif // NET_HTTP_SERVER_INTERNAL_EVHTTP_SERVER_H_ diff --git a/net_http/server/internal/server_support.h b/net_http/server/internal/server_support.h index c7f5ecc..e44085b 100644 --- a/net_http/server/internal/server_support.h +++ b/net_http/server/internal/server_support.h @@ -17,8 +17,8 @@ limitations under the License. // server object so the two are properly decoupled. // This may turn out to be generally useful with no libevents specifics. -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ +#ifndef NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ +#define NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ #include @@ -47,4 +47,4 @@ class ServerSupport { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ +#endif // NET_HTTP_SERVER_INTERNAL_SERVER_SUPPORT_H_ diff --git a/net_http/server/public/httpserver.h b/net_http/server/public/httpserver.h index 46916c4..53601e8 100644 --- a/net_http/server/public/httpserver.h +++ b/net_http/server/public/httpserver.h @@ -15,8 +15,8 @@ limitations under the License. // The entry point to access different HTTP server implementations. -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ +#ifndef NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ +#define NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ #include @@ -45,4 +45,4 @@ inline std::unique_ptr CreateEvHTTPServer( } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ +#endif // NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ diff --git a/net_http/server/public/httpserver_interface.h b/net_http/server/public/httpserver_interface.h index 52921bd..c153a09 100644 --- a/net_http/server/public/httpserver_interface.h +++ b/net_http/server/public/httpserver_interface.h @@ -15,8 +15,8 @@ limitations under the License. // APIs for the HTTP server. -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ +#ifndef NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ +#define NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ #include @@ -199,4 +199,4 @@ class HTTPServerInterface { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ +#endif // NET_HTTP_SERVER_PUBLIC_HTTPSERVER_INTERFACE_H_ diff --git a/net_http/server/public/server_request_interface.h b/net_http/server/public/server_request_interface.h index 8c8d67a..4fa1927 100644 --- a/net_http/server/public/server_request_interface.h +++ b/net_http/server/public/server_request_interface.h @@ -24,8 +24,8 @@ limitations under the License. // Streamed request/response APIs are to be added, which will introduce // additional API contract wrt the threading semantics. -#ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_ -#define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_ +#ifndef NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_ +#define NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_ #include #include @@ -204,4 +204,4 @@ inline void SetContentTypeTEXT(ServerRequestInterface* request) { } // namespace net_http -#endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_ +#endif // NET_HTTP_SERVER_PUBLIC_SERVER_REQUEST_INTERFACE_H_