vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 1 | /* |
| 2 | * |
Craig Tiller | 0605995 | 2015-02-18 08:34:56 -0800 | [diff] [blame] | 3 | * Copyright 2015, Google Inc. |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | * |
| 32 | */ |
| 33 | |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 34 | #include <cassert> |
| 35 | #include <memory> |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 36 | #include <mutex> |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 37 | #include <string> |
| 38 | #include <thread> |
| 39 | #include <vector> |
| 40 | #include <sstream> |
| 41 | |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 42 | #include <sys/signal.h> |
| 43 | |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 44 | #include <grpc/grpc.h> |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 45 | #include <grpc/support/alloc.h> |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 46 | #include <grpc/support/histogram.h> |
| 47 | #include <grpc/support/log.h> |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 48 | #include <grpc/support/host_port.h> |
Nicolas "Pixel" Noble | ba60820 | 2015-02-20 02:48:03 +0100 | [diff] [blame] | 49 | #include <gflags/gflags.h> |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 50 | #include <grpc++/client_context.h> |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 51 | #include <grpc++/status.h> |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 52 | #include <grpc++/server.h> |
| 53 | #include <grpc++/server_builder.h> |
Craig Tiller | 056ba54 | 2015-01-31 21:15:10 -0800 | [diff] [blame] | 54 | #include "test/core/util/grpc_profiler.h" |
yangg | 59dfc90 | 2014-12-19 14:00:14 -0800 | [diff] [blame] | 55 | #include "test/cpp/util/create_test_channel.h" |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 56 | #include "test/cpp/qps/client.h" |
vpai | 92fe70e | 2015-01-13 11:21:38 -0800 | [diff] [blame] | 57 | #include "test/cpp/qps/qpstest.pb.h" |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 58 | #include "test/cpp/qps/histogram.h" |
Craig Tiller | 2d0f36c | 2015-02-23 23:16:17 -0800 | [diff] [blame] | 59 | #include "test/cpp/qps/timer.h" |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 60 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 61 | namespace grpc { |
| 62 | namespace testing { |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 63 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 64 | class SynchronousClient GRPC_FINAL : public Client { |
| 65 | public: |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame^] | 66 | SynchronousClient(const ClientConfig& config) : Client(config) { |
| 67 | size_t num_threads = config.outstanding_rpcs_per_channel() * config.client_channels(); |
| 68 | responses_.resize(num_threads); |
| 69 | StartThreads(num_threads); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 70 | } |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 71 | |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame^] | 72 | ~SynchronousClient() { |
| 73 | EndThreads(); |
| 74 | } |
Nicolas "Pixel" Noble | 7e80efc | 2015-02-20 03:13:38 +0100 | [diff] [blame] | 75 | |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame^] | 76 | void ThreadFunc(Histogram* histogram, size_t thread_idx) { |
| 77 | auto* stub = channels_[thread_idx % channels_.size()].get_stub(); |
| 78 | double start = Timer::Now(); |
| 79 | grpc::ClientContext context; |
| 80 | grpc::Status s = stub->UnaryCall(&context, request_, &responses_[thread_idx]); |
| 81 | histogram->Add((Timer::Now() - start) * 1e9); |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 82 | } |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 83 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 84 | private: |
Craig Tiller | 8856875 | 2015-03-04 10:50:43 -0800 | [diff] [blame^] | 85 | std::vector<SimpleResponse> responses_; |
Craig Tiller | 5c004c6 | 2015-02-23 16:31:57 -0800 | [diff] [blame] | 86 | }; |
| 87 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 88 | std::unique_ptr<Client> CreateSynchronousClient(const ClientConfig& config) { |
| 89 | return std::unique_ptr<Client>(new SynchronousClient(config)); |
vpai | 80b6d01 | 2014-12-17 11:47:32 -0800 | [diff] [blame] | 90 | } |
| 91 | |
Craig Tiller | 6af9ed0 | 2015-03-02 22:42:10 -0800 | [diff] [blame] | 92 | } // namespace testing |
| 93 | } // namespace grpc |