mirror of https://github.com/grpc/grpc.git
commit
4671122995
97 changed files with 2031 additions and 585 deletions
@ -0,0 +1,52 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Grpc.Core.Internal.Tests |
||||
{ |
||||
public class CompletionQueueEventTest |
||||
{ |
||||
[Test] |
||||
public void CreateAndDestroy() |
||||
{ |
||||
Assert.AreEqual(CompletionQueueEvent.NativeSize, Marshal.SizeOf(typeof(CompletionQueueEvent))); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,64 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Threading.Tasks; |
||||
using Grpc.Core; |
||||
using Grpc.Core.Internal; |
||||
using Grpc.Core.Utils; |
||||
using NUnit.Framework; |
||||
|
||||
namespace Grpc.Core.Internal.Tests |
||||
{ |
||||
public class CompletionQueueSafeHandleTest |
||||
{ |
||||
[Test] |
||||
public void CreateAndDestroy() |
||||
{ |
||||
var cq = CompletionQueueSafeHandle.Create(); |
||||
cq.Dispose(); |
||||
} |
||||
|
||||
[Test] |
||||
public void CreateAndShutdown() |
||||
{ |
||||
var cq = CompletionQueueSafeHandle.Create(); |
||||
cq.Shutdown(); |
||||
var ev = cq.Next(); |
||||
cq.Dispose(); |
||||
Assert.AreEqual(GRPCCompletionType.Shutdown, ev.type); |
||||
Assert.AreNotEqual(IntPtr.Zero, ev.success); |
||||
Assert.AreEqual(IntPtr.Zero, ev.tag); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
|
||||
namespace Grpc.Core.Internal |
||||
{ |
||||
/// <summary> |
||||
/// grpc_event from grpc/grpc.h |
||||
/// </summary> |
||||
[StructLayout(LayoutKind.Sequential)] |
||||
internal struct CompletionQueueEvent |
||||
{ |
||||
[DllImport("grpc_csharp_ext.dll")] |
||||
static extern int grpcsharp_sizeof_grpc_event(); |
||||
|
||||
public GRPCCompletionType type; |
||||
public int success; |
||||
public IntPtr tag; |
||||
|
||||
internal static int NativeSize |
||||
{ |
||||
get |
||||
{ |
||||
return grpcsharp_sizeof_grpc_event(); |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@ |
||||
#region Copyright notice and license |
||||
|
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
#endregion |
||||
|
||||
using System; |
||||
using System.Collections.Concurrent; |
||||
using System.Collections.Generic; |
||||
using System.Runtime.InteropServices; |
||||
using Grpc.Core.Utils; |
||||
|
||||
namespace Grpc.Core.Internal |
||||
{ |
||||
internal delegate void OpCompletionDelegate(bool success); |
||||
|
||||
internal delegate void BatchCompletionDelegate(bool success, BatchContextSafeHandle ctx); |
||||
|
||||
internal class CompletionRegistry |
||||
{ |
||||
readonly ConcurrentDictionary<IntPtr, OpCompletionDelegate> dict = new ConcurrentDictionary<IntPtr, OpCompletionDelegate>(); |
||||
|
||||
public void Register(IntPtr key, OpCompletionDelegate callback) |
||||
{ |
||||
DebugStats.PendingBatchCompletions.Increment(); |
||||
Preconditions.CheckState(dict.TryAdd(key, callback)); |
||||
} |
||||
|
||||
public void RegisterBatchCompletion(BatchContextSafeHandle ctx, BatchCompletionDelegate callback) |
||||
{ |
||||
OpCompletionDelegate opCallback = ((success) => HandleBatchCompletion(success, ctx, callback)); |
||||
Register(ctx.Handle, opCallback); |
||||
} |
||||
|
||||
public OpCompletionDelegate Extract(IntPtr key) |
||||
{ |
||||
OpCompletionDelegate value; |
||||
Preconditions.CheckState(dict.TryRemove(key, out value)); |
||||
DebugStats.PendingBatchCompletions.Decrement(); |
||||
return value; |
||||
} |
||||
|
||||
private static void HandleBatchCompletion(bool success, BatchContextSafeHandle ctx, BatchCompletionDelegate callback) |
||||
{ |
||||
try |
||||
{ |
||||
callback(success, ctx); |
||||
} |
||||
catch (Exception e) |
||||
{ |
||||
Console.WriteLine("Exception occured while invoking completion delegate: " + e); |
||||
} |
||||
finally |
||||
{ |
||||
if (ctx != null) |
||||
{ |
||||
ctx.Dispose(); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,90 @@ |
||||
/* |
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
'use strict'; |
||||
|
||||
var assert = require('assert'); |
||||
|
||||
var common = require('../src/common.js'); |
||||
|
||||
var ProtoBuf = require('protobufjs'); |
||||
|
||||
var messages_proto = ProtoBuf.loadProtoFile( |
||||
__dirname + '/test_messages.proto').build(); |
||||
|
||||
describe('Proto message serialize and deserialize', function() { |
||||
var longSerialize = common.serializeCls(messages_proto.LongValues); |
||||
var longDeserialize = common.deserializeCls(messages_proto.LongValues); |
||||
var pos_value = '314159265358979'; |
||||
var neg_value = '-27182818284590'; |
||||
it('should preserve positive int64 values', function() { |
||||
var serialized = longSerialize({int_64: pos_value}); |
||||
assert.strictEqual(longDeserialize(serialized).int_64.toString(), |
||||
pos_value); |
||||
}); |
||||
it('should preserve negative int64 values', function() { |
||||
var serialized = longSerialize({int_64: neg_value}); |
||||
assert.strictEqual(longDeserialize(serialized).int_64.toString(), |
||||
neg_value); |
||||
}); |
||||
it('should preserve uint64 values', function() { |
||||
var serialized = longSerialize({uint_64: pos_value}); |
||||
assert.strictEqual(longDeserialize(serialized).uint_64.toString(), |
||||
pos_value); |
||||
}); |
||||
it('should preserve positive sint64 values', function() { |
||||
var serialized = longSerialize({sint_64: pos_value}); |
||||
assert.strictEqual(longDeserialize(serialized).sint_64.toString(), |
||||
pos_value); |
||||
}); |
||||
it('should preserve negative sint64 values', function() { |
||||
var serialized = longSerialize({sint_64: neg_value}); |
||||
assert.strictEqual(longDeserialize(serialized).sint_64.toString(), |
||||
neg_value); |
||||
}); |
||||
it('should preserve fixed64 values', function() { |
||||
var serialized = longSerialize({fixed_64: pos_value}); |
||||
assert.strictEqual(longDeserialize(serialized).fixed_64.toString(), |
||||
pos_value); |
||||
}); |
||||
it('should preserve positive sfixed64 values', function() { |
||||
var serialized = longSerialize({sfixed_64: pos_value}); |
||||
assert.strictEqual(longDeserialize(serialized).sfixed_64.toString(), |
||||
pos_value); |
||||
}); |
||||
it('should preserve negative sfixed64 values', function() { |
||||
var serialized = longSerialize({sfixed_64: neg_value}); |
||||
assert.strictEqual(longDeserialize(serialized).sfixed_64.toString(), |
||||
neg_value); |
||||
}); |
||||
}); |
@ -0,0 +1,38 @@ |
||||
// Copyright 2015, Google Inc. |
||||
// All rights reserved. |
||||
// |
||||
// Redistribution and use in source and binary forms, with or without |
||||
// modification, are permitted provided that the following conditions are |
||||
// met: |
||||
// |
||||
// * Redistributions of source code must retain the above copyright |
||||
// notice, this list of conditions and the following disclaimer. |
||||
// * Redistributions in binary form must reproduce the above |
||||
// copyright notice, this list of conditions and the following disclaimer |
||||
// in the documentation and/or other materials provided with the |
||||
// distribution. |
||||
// * Neither the name of Google Inc. nor the names of its |
||||
// contributors may be used to endorse or promote products derived from |
||||
// this software without specific prior written permission. |
||||
// |
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
|
||||
syntax = "proto3"; |
||||
|
||||
message LongValues { |
||||
int64 int_64 = 1; |
||||
uint64 uint_64 = 2; |
||||
sint64 sint_64 = 3; |
||||
fixed64 fixed_64 = 4; |
||||
sfixed64 sfixed_64 = 5; |
||||
} |
@ -1,3 +1,3 @@ |
||||
enum34==1.0.4 |
||||
futures==2.2.0 |
||||
protobuf==3.0.0a2 |
||||
protobuf==3.0.0a3 |
||||
|
@ -0,0 +1,178 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#ifndef TEST_QPS_INTERARRIVAL_H |
||||
#define TEST_QPS_INTERARRIVAL_H |
||||
|
||||
#include <chrono> |
||||
#include <cmath> |
||||
#include <random> |
||||
|
||||
#include <grpc++/config.h> |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
// First create classes that define a random distribution
|
||||
// Note that this code does not include C++-specific random distribution
|
||||
// features supported in std::random. Although this would make this code easier,
|
||||
// this code is required to serve as the template code for other language
|
||||
// stacks. Thus, this code only uses a uniform distribution of doubles [0,1)
|
||||
// and then provides the distribution functions itself.
|
||||
|
||||
class RandomDist { |
||||
public: |
||||
RandomDist() {} |
||||
virtual ~RandomDist() = 0; |
||||
// Argument to operator() is a uniform double in the range [0,1)
|
||||
virtual double operator()(double uni) const = 0; |
||||
}; |
||||
|
||||
inline RandomDist::~RandomDist() {} |
||||
|
||||
// ExpDist implements an exponential distribution, which is the
|
||||
// interarrival distribution for a Poisson process. The parameter
|
||||
// lambda is the mean rate of arrivals. This is the
|
||||
// most useful distribution since it is actually additive and
|
||||
// memoryless. It is a good representation of activity coming in from
|
||||
// independent identical stationary sources. For more information,
|
||||
// see http://en.wikipedia.org/wiki/Exponential_distribution
|
||||
|
||||
class ExpDist GRPC_FINAL : public RandomDist { |
||||
public: |
||||
explicit ExpDist(double lambda) : lambda_recip_(1.0 / lambda) {} |
||||
~ExpDist() GRPC_OVERRIDE {} |
||||
double operator()(double uni) const GRPC_OVERRIDE { |
||||
// Note: Use 1.0-uni above to avoid NaN if uni is 0
|
||||
return lambda_recip_ * (-log(1.0 - uni)); |
||||
} |
||||
|
||||
private: |
||||
double lambda_recip_; |
||||
}; |
||||
|
||||
// UniformDist implements a random distribution that has
|
||||
// interarrival time uniformly spread between [lo,hi). The
|
||||
// mean interarrival time is (lo+hi)/2. For more information,
|
||||
// see http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29
|
||||
|
||||
class UniformDist GRPC_FINAL : public RandomDist { |
||||
public: |
||||
UniformDist(double lo, double hi) : lo_(lo), range_(hi - lo) {} |
||||
~UniformDist() GRPC_OVERRIDE {} |
||||
double operator()(double uni) const GRPC_OVERRIDE { |
||||
return uni * range_ + lo_; |
||||
} |
||||
|
||||
private: |
||||
double lo_; |
||||
double range_; |
||||
}; |
||||
|
||||
// DetDist provides a random distribution with interarrival time
|
||||
// of val. Note that this is not additive, so using this on multiple
|
||||
// flows of control (threads within the same client or separate
|
||||
// clients) will not preserve any deterministic interarrival gap across
|
||||
// requests.
|
||||
|
||||
class DetDist GRPC_FINAL : public RandomDist { |
||||
public: |
||||
explicit DetDist(double val) : val_(val) {} |
||||
~DetDist() GRPC_OVERRIDE {} |
||||
double operator()(double uni) const GRPC_OVERRIDE { return val_; } |
||||
|
||||
private: |
||||
double val_; |
||||
}; |
||||
|
||||
// ParetoDist provides a random distribution with interarrival time
|
||||
// spread according to a Pareto (heavy-tailed) distribution. In this
|
||||
// model, many interarrival times are close to the base, but a sufficient
|
||||
// number will be high (up to infinity) as to disturb the mean. It is a
|
||||
// good representation of the response times of data center jobs. See
|
||||
// http://en.wikipedia.org/wiki/Pareto_distribution
|
||||
|
||||
class ParetoDist GRPC_FINAL : public RandomDist { |
||||
public: |
||||
ParetoDist(double base, double alpha) |
||||
: base_(base), alpha_recip_(1.0 / alpha) {} |
||||
~ParetoDist() GRPC_OVERRIDE {} |
||||
double operator()(double uni) const GRPC_OVERRIDE { |
||||
// Note: Use 1.0-uni above to avoid div by zero if uni is 0
|
||||
return base_ / pow(1.0 - uni, alpha_recip_); |
||||
} |
||||
|
||||
private: |
||||
double base_; |
||||
double alpha_recip_; |
||||
}; |
||||
|
||||
// A class library for generating pseudo-random interarrival times
|
||||
// in an efficient re-entrant way. The random table is built at construction
|
||||
// time, and each call must include the thread id of the invoker
|
||||
|
||||
typedef std::default_random_engine qps_random_engine; |
||||
|
||||
class InterarrivalTimer { |
||||
public: |
||||
InterarrivalTimer() {} |
||||
void init(const RandomDist& r, int threads, int entries = 1000000) { |
||||
qps_random_engine gen; |
||||
std::uniform_real_distribution<double> uniform(0.0, 1.0); |
||||
for (int i = 0; i < entries; i++) { |
||||
random_table_.push_back(std::chrono::nanoseconds( |
||||
static_cast<int64_t>(1e9 * r(uniform(gen))))); |
||||
} |
||||
// Now set up the thread positions
|
||||
for (int i = 0; i < threads; i++) { |
||||
thread_posns_.push_back(random_table_.begin() + (entries * i) / threads); |
||||
} |
||||
} |
||||
virtual ~InterarrivalTimer(){}; |
||||
|
||||
std::chrono::nanoseconds operator()(int thread_num) { |
||||
auto ret = *(thread_posns_[thread_num]++); |
||||
if (thread_posns_[thread_num] == random_table_.end()) |
||||
thread_posns_[thread_num] = random_table_.begin(); |
||||
return ret; |
||||
} |
||||
|
||||
private: |
||||
typedef std::vector<std::chrono::nanoseconds> time_table; |
||||
std::vector<time_table::const_iterator> thread_posns_; |
||||
time_table random_table_; |
||||
}; |
||||
} |
||||
} |
||||
|
||||
#endif |
@ -0,0 +1,76 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include "test/cpp/qps/interarrival.h" |
||||
#include <chrono> |
||||
#include <iostream> |
||||
|
||||
// Use the C histogram rather than C++ to avoid depending on proto
|
||||
#include <grpc/support/histogram.h> |
||||
#include <grpc++/config.h> |
||||
|
||||
using grpc::testing::RandomDist; |
||||
using grpc::testing::InterarrivalTimer; |
||||
|
||||
void RunTest(RandomDist&& r, int threads, std::string title) { |
||||
InterarrivalTimer timer; |
||||
timer.init(r, threads); |
||||
gpr_histogram *h(gpr_histogram_create(0.01, 60e9)); |
||||
|
||||
for (int i = 0; i < 10000000; i++) { |
||||
for (int j = 0; j < threads; j++) { |
||||
gpr_histogram_add(h, timer(j).count()); |
||||
} |
||||
} |
||||
|
||||
std::cout << title << " Distribution" << std::endl; |
||||
std::cout << "Value, Percentile" << std::endl; |
||||
for (double pct = 0.0; pct < 100.0; pct += 1.0) { |
||||
std::cout << gpr_histogram_percentile(h, pct) << "," << pct << std::endl; |
||||
} |
||||
|
||||
gpr_histogram_destroy(h); |
||||
} |
||||
|
||||
using grpc::testing::ExpDist; |
||||
using grpc::testing::DetDist; |
||||
using grpc::testing::UniformDist; |
||||
using grpc::testing::ParetoDist; |
||||
|
||||
int main(int argc, char **argv) { |
||||
RunTest(ExpDist(10.0), 5, std::string("Exponential(10)")); |
||||
RunTest(DetDist(5.0), 5, std::string("Det(5)")); |
||||
RunTest(UniformDist(0.0, 10.0), 5, std::string("Uniform(1,10)")); |
||||
RunTest(ParetoDist(1.0, 1.0), 5, std::string("Pareto(1,1)")); |
||||
return 0; |
||||
} |
@ -0,0 +1,87 @@ |
||||
/*
|
||||
* |
||||
* Copyright 2015, Google Inc. |
||||
* All rights reserved. |
||||
* |
||||
* Redistribution and use in source and binary forms, with or without |
||||
* modification, are permitted provided that the following conditions are |
||||
* met: |
||||
* |
||||
* * Redistributions of source code must retain the above copyright |
||||
* notice, this list of conditions and the following disclaimer. |
||||
* * Redistributions in binary form must reproduce the above |
||||
* copyright notice, this list of conditions and the following disclaimer |
||||
* in the documentation and/or other materials provided with the |
||||
* distribution. |
||||
* * Neither the name of Google Inc. nor the names of its |
||||
* contributors may be used to endorse or promote products derived from |
||||
* this software without specific prior written permission. |
||||
* |
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||||
* |
||||
*/ |
||||
|
||||
#include <set> |
||||
|
||||
#include <grpc/support/log.h> |
||||
|
||||
#include <signal.h> |
||||
|
||||
#include "test/cpp/qps/driver.h" |
||||
#include "test/cpp/qps/report.h" |
||||
#include "test/cpp/util/benchmark_config.h" |
||||
|
||||
namespace grpc { |
||||
namespace testing { |
||||
|
||||
static const int WARMUP = 5; |
||||
static const int BENCHMARK = 10; |
||||
|
||||
static void RunQPS() { |
||||
gpr_log(GPR_INFO, "Running QPS test, open-loop"); |
||||
|
||||
ClientConfig client_config; |
||||
client_config.set_client_type(ASYNC_CLIENT); |
||||
client_config.set_enable_ssl(false); |
||||
client_config.set_outstanding_rpcs_per_channel(1000); |
||||
client_config.set_client_channels(8); |
||||
client_config.set_payload_size(1); |
||||
client_config.set_async_client_threads(8); |
||||
client_config.set_rpc_type(UNARY); |
||||
client_config.set_load_type(POISSON); |
||||
client_config.mutable_load_params()-> |
||||
mutable_poisson()->set_offered_load(10000.0); |
||||
|
||||
ServerConfig server_config; |
||||
server_config.set_server_type(ASYNC_SERVER); |
||||
server_config.set_enable_ssl(false); |
||||
server_config.set_threads(4); |
||||
|
||||
const auto result = |
||||
RunScenario(client_config, 1, server_config, 1, WARMUP, BENCHMARK, -2); |
||||
|
||||
GetReporter()->ReportQPSPerCore(*result); |
||||
GetReporter()->ReportLatency(*result); |
||||
} |
||||
|
||||
} // namespace testing
|
||||
} // namespace grpc
|
||||
|
||||
int main(int argc, char** argv) { |
||||
grpc::testing::InitBenchmark(&argc, &argv, true); |
||||
|
||||
signal(SIGPIPE, SIG_IGN); |
||||
grpc::testing::RunQPS(); |
||||
|
||||
return 0; |
||||
} |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue