forked from facebookincubator/velox
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
misc: Remote vs. Local Velox function benchmark (facebookincubator#11539
) Summary: Pull Request resolved: facebookincubator#11539 Benchmark Velox udfs with Remote function execution vs. local execution. Reviewed By: pedroerp Differential Revision: D65694860 fbshipit-source-id: 3d586248117e5bc05278e7e92e719d6c99bf25e9
- Loading branch information
1 parent
7056ab2
commit 9b64b94
Showing
3 changed files
with
155 additions
and
0 deletions.
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; | ||
} |