コード例 #1
0
 public async Task SpawnEntities()
 {
     for (var i = 0; i < EntityCount; i++)
     {
         var msg = new ShardedMessage(i.ToString(), i);
         await _shardRegion1.Ask <ShardedMessage>(msg);
     }
 }
コード例 #2
0
        public async Task Setup()
        {
            var config = StateMode switch
            {
                StateStoreMode.Persistence => CreatePersistenceConfig(),
                StateStoreMode.DData => CreateDDataConfig(),
                _ => null
            };

            _sys1 = ActorSystem.Create("BenchSys", config);
            _sys2 = ActorSystem.Create("BenchSys", config);

            var c1 = Cluster.Get(_sys1);
            var c2 = Cluster.Get(_sys2);

            await c1.JoinAsync(c1.SelfAddress);

            await c2.JoinAsync(c1.SelfAddress);

            _shardRegion1 = StartShardRegion(_sys1);
            _shardRegion2 = StartShardRegion(_sys2);

            _localRouter = _sys1.ActorOf(Props.Create <ShardedProxyEntityActor>(_shardRegion1).WithRouter(new RoundRobinPool(1000)));

            var s1Asks = new List <Task <ShardedEntityActor.ResolveResp> >(20);
            var s2Asks = new List <Task <ShardedEntityActor.ResolveResp> >(20);

            foreach (var i in Enumerable.Range(0, 20))
            {
                s1Asks.Add(_shardRegion1.Ask <ShardedEntityActor.ResolveResp>(new ShardingEnvelope(i.ToString(), ShardedEntityActor.Resolve.Instance), TimeSpan.FromSeconds(3)));
                s2Asks.Add(_shardRegion2.Ask <ShardedEntityActor.ResolveResp>(new ShardingEnvelope(i.ToString(), ShardedEntityActor.Resolve.Instance), TimeSpan.FromSeconds(3)));
            }

            // wait for all Ask operations to complete
            await Task.WhenAll(s1Asks.Concat(s2Asks));

            _entityOnSys2 = s1Asks.First(x => x.Result.Addr.Equals(c2.SelfAddress)).Result.EntityId;
            _entityOnSys1 = s2Asks.First(x => x.Result.Addr.Equals(c1.SelfAddress)).Result.EntityId;

            _messageToSys1 = new ShardedMessage(_entityOnSys1, 10);
            _messageToSys2 = new ShardedMessage(_entityOnSys2, 10);
        }
コード例 #3
0
 public SendShardedMessage(string entityId, ShardedMessage message)
 {
     EntityId = entityId;
     Message  = message;
 }
コード例 #4
0
 public BeginSend(ShardedMessage msg, IActorRef target, int batchSize)
 {
     Msg       = msg;
     Target    = target;
     BatchSize = batchSize;
 }