-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
misc: Remote vs. Local Velox function benchmark #11539
Closed
emilysun201309
wants to merge
2
commits into
facebookincubator:main
from
emilysun201309:export-D65694860
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# 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. | ||
|
||
add_executable(velox_benchmark_local_remote_comparison | ||
LocalRemoteComparisonBenchmark.cpp) | ||
|
||
target_link_libraries( | ||
velox_benchmark_local_remote_comparison | ||
PUBLIC velox_type | ||
velox_benchmark_builder | ||
velox_vector_test_lib | ||
velox_function_registry | ||
velox_functions_remote | ||
velox_functions_remote_utils | ||
Folly::folly | ||
Folly::follybenchmark | ||
gflags::gflags | ||
glog::glog) |
125 changes: 125 additions & 0 deletions
125
velox/functions/remote/benchmarks/LocalRemoteComparisonBenchmark.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include <folly/Benchmark.h> | ||
#include <folly/init/Init.h> | ||
|
||
#include "velox/benchmarks/ExpressionBenchmarkBuilder.h" | ||
#include "velox/functions/Registerer.h" | ||
#include "velox/functions/prestosql/Arithmetic.h" | ||
#include "velox/functions/prestosql/StringFunctions.h" | ||
#include "velox/functions/prestosql/URLFunctions.h" | ||
#include "velox/functions/remote/client/Remote.h" | ||
#include "velox/functions/remote/utils/RemoteFunctionServiceProvider.h" | ||
#include "velox/type/Type.h" | ||
|
||
using namespace facebook::velox; | ||
using namespace facebook::velox::functions; | ||
|
||
DEFINE_int32(batch_size, 1000, "Batch size for benchmarks"); | ||
|
||
int main(int argc, char** argv) { | ||
folly::Init init(&argc, &argv); | ||
memory::MemoryManager::initialize({}); | ||
|
||
auto param = startLocalThriftServiceAndGetParams(); | ||
RemoteVectorFunctionMetadata metadata; | ||
metadata.location = param.serverAddress; | ||
|
||
// Register the remote adapter for PlusFunction | ||
auto plusSignatures = {exec::FunctionSignatureBuilder() | ||
.returnType("bigint") | ||
.argumentType("bigint") | ||
.argumentType("bigint") | ||
.build()}; | ||
registerRemoteFunction("remote_plus", plusSignatures, metadata); | ||
// Registers the actual function under a different prefix. This is only | ||
// needed when thrift service runs in the same process. | ||
registerFunction<PlusFunction, int64_t, int64_t, int64_t>( | ||
{param.functionPrefix + ".remote_plus"}); | ||
// register this function again, because the benchmark builder somehow doesn't | ||
// recognize the function registered above (remote.xxx). | ||
registerFunction<PlusFunction, int64_t, int64_t, int64_t>({"plus"}); | ||
|
||
// Register the remote adapter for SubstrFunction | ||
auto substrSignatures = {exec::FunctionSignatureBuilder() | ||
.returnType("varchar") | ||
.argumentType("varchar") | ||
.argumentType("integer") | ||
.build()}; | ||
registerRemoteFunction("remote_substr", substrSignatures, metadata); | ||
registerFunction<SubstrFunction, Varchar, Varchar, int32_t>( | ||
{param.functionPrefix + ".remote_substr"}); | ||
registerFunction<SubstrFunction, Varchar, Varchar, int32_t>({"substr"}); | ||
|
||
// Register the remote adapter for UrlEncodeFunction | ||
auto urlSignatures = {exec::FunctionSignatureBuilder() | ||
.returnType("varchar") | ||
.argumentType("varchar") | ||
.build()}; | ||
registerRemoteFunction("remote_url_encode", urlSignatures, metadata); | ||
registerFunction<UrlEncodeFunction, Varchar, Varchar>( | ||
{param.functionPrefix + ".remote_url_encode"}); | ||
registerFunction<UrlEncodeFunction, Varchar, Varchar>({"url_encode"}); | ||
|
||
ExpressionBenchmarkBuilder benchmarkBuilder; | ||
|
||
VectorFuzzer::Options opts; | ||
opts.vectorSize = FLAGS_batch_size; | ||
opts.stringVariableLength = true; | ||
opts.containerVariableLength = true; | ||
VectorFuzzer fuzzer(opts, benchmarkBuilder.pool()); | ||
auto vectorMaker = benchmarkBuilder.vectorMaker(); | ||
|
||
// benchmark comparaing PlusFunction running locally (same thread) | ||
// and running with RemoteFunction (different threads). | ||
benchmarkBuilder | ||
.addBenchmarkSet( | ||
"local_vs_remote_plus", | ||
vectorMaker.rowVector( | ||
{"c0", "c1"}, | ||
{fuzzer.fuzzFlat(BIGINT()), fuzzer.fuzzFlat(BIGINT())})) | ||
.addExpression("local_plus", "plus(c0, c1) ") | ||
.addExpression("remote_plus", "remote_plus(c0, c1) ") | ||
.withIterations(1000); | ||
|
||
// benchmark comparaing SubstrFunction running locally (same thread) | ||
// and running with RemoteFunction (different threads). | ||
benchmarkBuilder | ||
.addBenchmarkSet( | ||
"local_vs_remote_substr", | ||
vectorMaker.rowVector( | ||
{"c0", "c1"}, | ||
{fuzzer.fuzzFlat(VARCHAR()), fuzzer.fuzzFlat(INTEGER())})) | ||
.addExpression("local_substr", "substr(c0, c1) ") | ||
.addExpression("remote_substr", "remote_substr(c0, c1) ") | ||
.withIterations(1000); | ||
|
||
// benchmark comparaing UrlEncodeFunction running locally (same thread) | ||
// and running with RemoteFunction (different threads). | ||
benchmarkBuilder | ||
.addBenchmarkSet( | ||
"local_vs_remote_url_encode", | ||
vectorMaker.rowVector({"c0"}, {fuzzer.fuzzFlat(VARCHAR())})) | ||
.addExpression("local_url_encode", "url_encode(c0) ") | ||
.addExpression("remote_url_encode", "remote_url_encode(c0) ") | ||
.withIterations(1000); | ||
|
||
benchmarkBuilder.registerBenchmarks(); | ||
benchmarkBuilder.testBenchmarks(); | ||
folly::runBenchmarks(); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright (c) Facebook, Inc. and its affiliates. | ||
# | ||
# 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. | ||
|
||
add_library(velox_functions_remote_utils RemoteFunctionServiceProvider.cpp) | ||
|
||
target_link_libraries( | ||
velox_functions_remote_utils | ||
PUBLIC velox_functions_remote_server) |
76 changes: 76 additions & 0 deletions
76
velox/functions/remote/utils/RemoteFunctionServiceProvider.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* 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. | ||
*/ | ||
|
||
#include "velox/functions/remote/utils/RemoteFunctionServiceProvider.h" | ||
|
||
#include "thrift/lib/cpp2/server/ThriftServer.h" | ||
#include "velox/functions/remote/server/RemoteFunctionService.h" | ||
|
||
namespace facebook::velox::functions { | ||
|
||
RemoteFunctionServiceParams | ||
RemoteFunctionServiceProviderForLocalThrift::getRemoteFunctionServiceParams() { | ||
folly::call_once(initializeServiceFlag_, [&]() { initializeServer(); }); | ||
return RemoteFunctionServiceParams{ | ||
remotePrefix_, | ||
location_, | ||
}; | ||
} | ||
|
||
void RemoteFunctionServiceProviderForLocalThrift::initializeServer() { | ||
auto handler = | ||
std::make_shared<velox::functions::RemoteFunctionServiceHandler>( | ||
remotePrefix_); | ||
server_ = std::make_shared<apache::thrift::ThriftServer>(); | ||
server_->setInterface(handler); | ||
server_->setAddress(location_); | ||
|
||
thread_ = std::make_unique<std::thread>([&] { server_->serve(); }); | ||
VELOX_CHECK(waitForRunning(), "Unable to initialize thrift server."); | ||
LOG(INFO) << "Thrift server is up and running in local port " << location_; | ||
} | ||
|
||
bool RemoteFunctionServiceProviderForLocalThrift::waitForRunning() { | ||
for (size_t i = 0; i < 100; ++i) { | ||
if (server_->getServerStatus() == | ||
apache::thrift::ThriftServer::ServerStatus::RUNNING) { | ||
return true; | ||
} | ||
std::this_thread::sleep_for(std::chrono::milliseconds(500)); | ||
} | ||
return false; | ||
} | ||
|
||
RemoteFunctionServiceProviderForLocalThrift:: | ||
~RemoteFunctionServiceProviderForLocalThrift() { | ||
server_->stop(); | ||
thread_->join(); | ||
LOG(INFO) << "Thrift server stopped."; | ||
} | ||
|
||
RemoteFunctionServiceParams startLocalThriftServiceAndGetParams() { | ||
static folly::Singleton<IRemoteFunctionServiceProvider> | ||
remoteFunctionServiceProviderForLocalThriftSingleton{ | ||
[]() { return new RemoteFunctionServiceProviderForLocalThrift(); }}; | ||
auto provider = | ||
remoteFunctionServiceProviderForLocalThriftSingleton.try_get(); | ||
if (!provider) { | ||
throw std::runtime_error("local remoteFunctionProvider is not available"); | ||
} | ||
return provider->getRemoteFunctionServiceParams(); | ||
} | ||
|
||
} // namespace facebook::velox::functions |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmarks must be enclosed under the
VELOX_ENABLE_BENCHMARKS
CMake option.CC: @amitkdutta
@czentgr is opening a fix.