Пример #1
0
        public static async Task RunAsync([PerperModuleTrigger(RunOnStartup = true)]
                                          PerperModuleContext context,
                                          CancellationToken cancellationToken)
        {
            var slotCount = 20; // 30

            var pingChainId = Guid.NewGuid();
            var pongChainId = Guid.NewGuid();

            // For test harness we create seed blocks with valid references in the states
            var pingReference = Guid.NewGuid();
            var pongReference = Guid.NewGuid();

            var slotGossips = await context.StreamFunctionAsync("DummyStream", new { });

            await context.StreamActionAsync("Apocryph.Runtime.FunctionApp.ChainListStream.Run", new
            {
                slotGossips,
                chains = new Dictionary <Guid, Chain>
                {
                    { pingChainId, new Chain(slotCount, new Block(
                                                 new Hash(new byte[] {}),
                                                 pingChainId,
                                                 null,
                                                 Guid.NewGuid(),
                                                 new Dictionary <string, byte[]>
                        {
                            {
                                typeof(ChainAgentPing).FullName !+".Run",
                                JsonSerializer.SerializeToUtf8Bytes(new ChainAgentState {
                                    OtherReference = pongReference
                                })
                            },
Пример #2
0
        public async Task <IPerperStream> StartAsync(
            [PerperModuleTrigger] PerperModuleContext context,
            [Perper("input")] IPerperStream input,
            CancellationToken cancellationToken,
            ILogger logger)
        {
            logger.LogInformation("Started AgentPong module...");

            var runtimeStream = await context.StreamFunctionAsync(typeof(AgentPongRuntimeStream), new { input = input.Subscribe() });

            return(runtimeStream);
        }
Пример #3
0
        private async Task ListenAsync(CancellationToken cancellationToken)
        {
            var triggers = _context.GetNotifications(_delegateName).WorkerTriggers(cancellationToken);

            await foreach (var(streamName, workerName) in triggers.WithCancellation(cancellationToken))
            {
                var triggerValue = new PerperModuleContext(streamName, _delegateName, workerName, _context);
                await _executor.TryExecuteAsync(
                    new TriggeredFunctionData { TriggerValue = triggerValue },
                    cancellationToken);
            }
        }
Пример #4
0
        public static async Task RunAsync([PerperModuleTrigger(RunOnStartup = true)]
                                          PerperModuleContext context,
                                          CancellationToken cancellationToken)
        {
            await using var multiGenerator =
                            await context.StreamFunctionAsync("NamedGeneratorGenerator", typeof(GeneratorGenerator), new { count = 40 });

            await using var coallator =
                            await context.StreamFunctionAsync("NamedCoallator", typeof(Coallator), new { inputs = multiGenerator.Subscribe() });

            await using var consumer =
                            await context.StreamActionAsync("NamedPassthroughConsumer", typeof(PassthroughConsumer), new { processor = coallator });

            await context.BindOutput(cancellationToken);
        }
Пример #5
0
        public async Task StartAsync(
            [PerperModuleTrigger(RunOnStartup = true)] PerperModuleContext context,
            CancellationToken cancellationToken,
            ILogger logger)
        {
            logger.LogInformation("Started Perper Structure sample application...");

            var pingInputStream  = context.DeclareStream(typeof(InputProviderStream));
            var pingOutputStream = await context.StartChildModuleAsync <IPerperStream>("ping", new { input = pingInputStream }, cancellationToken);

            var pongInputStream  = context.DeclareStream(typeof(InputProviderStream));
            var pongOutputStream = await context.StartChildModuleAsync <IPerperStream>("pong", new { input = pongInputStream }, cancellationToken);

            await context.StreamFunctionAsync(pingInputStream, new { input = pongOutputStream });

            await context.StreamFunctionAsync(pongInputStream, new { input = pingOutputStream });

            await context.StreamActionAsync(typeof(EnvironmentMonitorStream),
                                            new
            {
                agentPingOutput = pingOutputStream.Subscribe(),
                agentPongOutput = pongOutputStream.Subscribe()
            });
        }
Пример #6
0
        public async Task Run([PerperModuleTrigger(RunOnStartup = true)] PerperModuleContext context,
                              CancellationToken cancellationToken)
        {
            var streams = new List <IPerperStream>();

            for (var i = 0; i < NodeCount; i++)
            {
                var stream = context.DeclareStream("Node-" + i, typeof(Node), typeof(Message));
                streams.Add(stream);
            }

            var peering = await context.StreamFunctionAsync("Peering", typeof(Peering), new
            {
                streams = streams.ToArray()
            }, typeof(Message));

            var dummy = await context.StreamFunctionAsync("DummyInput", "Dummy", new { }, typeof(Message));

            for (var i = 0; i < NodeCount; i++)
            {
                await context.StreamFunctionAsync(streams[i], new
                {
                    enumerated = (EnumerateMessages ? peering : dummy).Subscribe(),
                    filtered   = (FilterMessages ? peering : dummy).Filter("To", i).Subscribe(),
                    queried    = (QueryMessages ? streams.ToArray() : new IPerperStream[0] {
                    }),
                    i,
                    n = NodeCount,
                });
            }

            await context.StreamActionAsync("Dummy", new
            {
                peering = peering.Subscribe()
            });

            while (!NodesReady.IsMax())
            {
                await Task.Delay(100);
            }
            var columns = "| {0,10}";

            if (EnumerateMessages)
            {
                columns += " | {1,10}";
            }
            if (FilterMessages)
            {
                columns += " | {2,10}";
            }
            if (QueryMessages)
            {
                columns += " | {3,10}";
            }
            columns += " | {4,10} |";
            var stats   = new[] { MessagesSent.Read(), MessagesEnumerated.Read(), MessagesFiltered.Read(), MessagesQueried.Read(), MessagesProcessed.Read() };
            var seconds = 0;

            Console.WriteLine("Sending {0} messages between {1} nodes", MessagesSent.Max, NodesReady.Max);
            Console.WriteLine("Per-second values:");
            Console.WriteLine(columns, "Sent", "Enumerated", "Filtered", "Queried", "Processed");
            Console.WriteLine(columns, "-", "-", "-", "-", "-");
            while (true)
            {
                seconds += 1;
                cancellationToken.ThrowIfCancellationRequested();
                await Task.Delay(1000, cancellationToken);

                var values = stats.Select(x => (object)x.Advance()).ToArray();
                Console.WriteLine(columns, values);

                if ((long)values[4] == 0L)
                {
                    break; // Nothing processed in the last second, assume finished
                }
            }
            Console.WriteLine("Sent {0} messages between {1} nodes in roughly {2} seconds", MessagesSent.Get(), NodesReady.Get(), seconds);
        }