Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Side by Side Diff: third_party/grpc/src/node/performance/worker_service_impl.js

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 *
3 * Copyright 2015-2016, Google Inc.
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
34 'use strict';
35
36 var os = require('os');
37 var BenchmarkClient = require('./benchmark_client');
38 var BenchmarkServer = require('./benchmark_server');
39
40 exports.quitWorker = function quitWorker(call, callback) {
41 callback(null, {});
42 process.exit(0);
43 }
44
45 exports.runClient = function runClient(call) {
46 var client;
47 call.on('data', function(request) {
48 var stats;
49 switch (request.argtype) {
50 case 'setup':
51 var setup = request.setup;
52 client = new BenchmarkClient(setup.server_targets,
53 setup.client_channels,
54 setup.histogram_params,
55 setup.security_params);
56 client.on('error', function(error) {
57 call.emit('error', error);
58 });
59 switch (setup.load_params.load) {
60 case 'closed_loop':
61 client.startClosedLoop(setup.outstanding_rpcs_per_channel,
62 setup.rpc_type,
63 setup.payload_config.simple_params.req_size,
64 setup.payload_config.simple_params.resp_size);
65 break;
66 case 'poisson':
67 client.startPoisson(setup.outstanding_rpcs_per_channel,
68 setup.rpc_type, setup.payload_config.req_size,
69 setup.payload_config.resp_size,
70 setup.load_params.poisson.offered_load);
71 break;
72 default:
73 call.emit('error', new Error('Unsupported LoadParams type' +
74 setup.load_params.load));
75 }
76 stats = client.mark();
77 call.write({
78 stats: stats
79 });
80 break;
81 case 'mark':
82 if (client) {
83 stats = client.mark(request.mark.reset);
84 call.write({
85 stats: stats
86 });
87 } else {
88 call.emit('error', new Error('Got Mark before ClientConfig'));
89 }
90 break;
91 default:
92 throw new Error('Nonexistent client argtype option: ' + request.argtype);
93 }
94 });
95 call.on('end', function() {
96 client.stop(function() {
97 call.end();
98 });
99 });
100 };
101
102 exports.runServer = function runServer(call) {
103 var server;
104 call.on('data', function(request) {
105 var stats;
106 switch (request.argtype) {
107 case 'setup':
108 server = new BenchmarkServer('[::]', request.setup.port,
109 request.setup.security_params);
110 server.start();
111 stats = server.mark();
112 call.write({
113 stats: stats,
114 port: server.getPort()
115 });
116 break;
117 case 'mark':
118 if (server) {
119 stats = server.mark(request.mark.reset);
120 call.write({
121 stats: stats,
122 port: server.getPort(),
123 cores: 1
124 });
125 } else {
126 call.emit('error', new Error('Got Mark before ServerConfig'));
127 }
128 break;
129 default:
130 throw new Error('Nonexistent server argtype option');
131 }
132 });
133 call.on('end', function() {
134 server.stop(function() {
135 call.end();
136 });
137 });
138 };
139
140 exports.coreCount = function coreCount(call, callback) {
141 callback(null, {cores: os.cpus().length});
142 };
OLDNEW
« no previous file with comments | « third_party/grpc/src/node/performance/worker.js ('k') | third_party/grpc/src/node/src/client.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698