Ejemplo n.º 1
0
        static MessageBenchmark()
        {
            var body = new Response("yess!");

            Value = (new Message
            {
                TargetActivation = ActivationId.NewId(),
                TargetSilo = SiloAddress.New(IPEndPoint.Parse("210.50.4.44:40902"), 5423123),
                TargetGrain = GrainId.Create("sys.mygrain", "borken_thee_doggo"),
                BodyObject = body,
                InterfaceType = GrainInterfaceType.Create("imygrain"),
                SendingActivation = ActivationId.NewId(),
                SendingSilo = SiloAddress.New(IPEndPoint.Parse("10.50.4.44:40902"), 5423123),
                SendingGrain = GrainId.Create("sys.mygrain", "fluffy_g"),
                TraceContext = new TraceContext {
                    ActivityId = Guid.NewGuid()
                },
                Id = CorrelationId.GetNext()
            }).Headers;

            //
            var services = new ServiceCollection()
                           .AddSerializer()
                           .BuildServiceProvider();

            Serializer = services.GetRequiredService <Serializer <Message.HeadersContainer> >();
            var bytes = new byte[4000];

            Session = services.GetRequiredService <SerializerSessionPool>().GetSession();
            var writer = new SingleSegmentBuffer(bytes).CreateWriter(Session);

            Serializer.Serialize(Value, ref writer);
            Input = bytes;
        }
Ejemplo n.º 2
0
        static MegaGraphBenchmark()
        {
            const int Size = 250_000;

            Value = new Dictionary <string, int>(Size);
            for (var i = 0; i < Size; i++)
            {
                Value[i.ToString(CultureInfo.InvariantCulture)] = i;
            }

            var services = new ServiceCollection()
                           .AddSerializer()
                           .BuildServiceProvider();

            Serializer = services.GetRequiredService <Serializer <Dictionary <string, int> > >();
            Session    = services.GetRequiredService <SerializerSessionPool>().GetSession();
            var pipe   = new Pipe(new PipeOptions(readerScheduler: PipeScheduler.Inline, writerScheduler: PipeScheduler.Inline));
            var writer = pipe.Writer.CreateWriter(Session);

            Serializer.Serialize(Value, ref writer);
            pipe.Writer.FlushAsync();
            pipe.Reader.TryRead(out var result);
            Input = result.Buffer.ToArray();
        }
Ejemplo n.º 3
0
 private void ReturnSession(SerializerSession session) => _sessionPool.Return(session);