コード例 #1
0
        public void LeastShardAllocationStrategy_must_not_pick_shards_that_are_in_progress()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 3, maxSimultaneousRebalance: 4);
            var allocations        = CreateAllocations(aCount: 10);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("002").Add("003")).Result.Should().BeEquivalentTo("001", "004");
        }
コード例 #2
0
        public void LeastShardAllocationStrategy_must_allocate_to_region_with_least_number_of_shards()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 3, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 1, bCount: 1);

            allocationStrategy.AllocateShard(_regionA, "003", allocations).Result.Should().Be(_regionC);
        }
コード例 #3
0
        public void LeastShardAllocationStrategy_must_not_rebalance_when_diff_equal_to_threshold_2_2_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 2, bCount: 2);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEmpty();
        }
コード例 #4
0
        public void LeastShardAllocationStrategy_must_limit_number_of_simultaneous_rebalance()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 3, maxSimultaneousRebalance: 2);
            var allocations        = CreateAllocations(aCount: 1, bCount: 10);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("002", "003");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("002").Add("003")).Result.Should().BeEmpty();
        }
コード例 #5
0
        public void LeastShardAllocationStrategy_must_rebalance_from_region_with_most_number_of_shards_4_4_0_rebalanceThreshold_1()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 1, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 4, bCount: 4);

            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("001");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001")).Result.Should().BeEquivalentTo("005");
        }
コード例 #6
0
        private Props CoordinatorProps(string typeName, bool rebalanceEntities)
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);
            var config             = ConfigurationFactory.ParseString(string.Format(""));
            var settings           = ClusterShardingSettings.Create(config, Sys.Settings.Config.GetConfig("akka.cluster.singleton"));

            return(PersistentShardCoordinator.Props(typeName, settings, allocationStrategy));
        }
コード例 #7
0
        private void StartSharding(ActorSystem sys, IActorRef probe)
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);

            ClusterSharding.Get(sys).Start(
                typeName: "Entity",
                entityProps: Props.Create(() => new TestEntity(probe)),
                settings: ClusterShardingSettings.Create(Sys).WithRememberEntities(true),
                extractEntityId: extractEntityId,
                extractShardId: extractShardId);
        }
コード例 #8
0
        public void LeastShardAllocationStrategy_must_rebalance_from_region_with_most_number_of_shards_5_5_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 5, bCount: 5);

            // optimal would => [4, 4, 2] or even => [3, 4, 3]
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("001", "002");
            // if 001 and 002 are not started quickly enough this is stopping more than optimal
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001").Add("002")).Result.Should().BeEquivalentTo("006", "007");
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty.Add("001").Add("002").Add("006").Add("007")).Result.Should().BeEquivalentTo("003");
        }
コード例 #9
0
        public void LeastShardAllocationStrategy_must_rebalance_rebalance_from_region_with_most_number_of_shards_1_3_0_rebalanceThreshold_2()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(rebalanceThreshold: 2, maxSimultaneousRebalance: 10);
            var allocations        = CreateAllocations(aCount: 1, bCount: 2);

            // so far regionB has 2 shards and regionC has 0 shards, but the diff is <= rebalanceThreshold
            allocationStrategy.Rebalance(allocations, ImmutableHashSet <string> .Empty).Result.Should().BeEmpty();

            var allocations2 = CreateAllocations(aCount: 1, bCount: 3);

            allocationStrategy.Rebalance(allocations2, ImmutableHashSet <string> .Empty).Result.Should().BeEquivalentTo("002");
            allocationStrategy.Rebalance(allocations2, ImmutableHashSet <string> .Empty.Add("002")).Result.Should().BeEmpty();
        }
コード例 #10
0
        private void StartSharding()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);

            ClusterSharding.Get(Sys).Start(
                typeName: "Entity",
                entityProps: Props.Create <Entity>(),
                settings: ClusterShardingSettings.Create(Sys),
                extractEntityId: extractEntityId,
                extractShardId: extractShardId,
                allocationStrategy: allocationStrategy,
                handOffStopMessage: StopEntity.Instance);
        }
コード例 #11
0
        private Props CoordinatorProps(string typeName, bool rebalanceEntities, bool rememberEntities)
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);
            var config             = ConfigurationFactory.ParseString(string.Format(@"
                handoff-timeout = 10s
                shard-start-timeout = 10s
                rebalance-interval = " + (rebalanceEntities ? "2s" : "3600s")))
                                     .WithFallback(Sys.Settings.Config.GetConfig("akka.cluster.sharding"));
            var settings = ClusterShardingSettings.Create(config, Sys.Settings.Config.GetConfig("akka.cluster.singleton"))
                           .WithRememberEntities(rememberEntities);

            return(PersistentShardCoordinator.Props(typeName, settings, allocationStrategy));
        }
コード例 #12
0
        public void LeastShardAllocationStrategy_dont_rebalance_excessive_shards_if_maxSimultaneousRebalance_gt_rebalanceThreshold()
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 5);
            var allocations        = new Dictionary <IActorRef, IImmutableList <string> >
            {
                { _regionA, new [] { "shard1", "shard2", "shard3", "shard4", "shard5", "shard6", "shard7", "shard8" }.ToImmutableList() },
                { _regionB, new [] { "shard9", "shard10", "shard11", "shard12" }.ToImmutableList() }
            }.ToImmutableDictionary();

            var r1 = allocationStrategy.Rebalance(allocations, ImmutableHashSet.Create("shard2")).Result;

            r1.Should().BeEquivalentTo(new[] { "shard1", "shard3", "shard4" });

            var r2 = _allocationStrategy.Rebalance(allocations, ImmutableHashSet.Create("shard5", "shard6", "shard7", "shard8")).Result;

            r2.Count.Should().Be(0);
        }
コード例 #13
0
        public void ClusterSharding_should_gracefully_shutdown_empty_region()
        {
            Within(TimeSpan.FromSeconds(30), () =>
            {
                RunOn(() =>
                {
                    var allocationStrategy = new LeastShardAllocationStrategy(2, 1);
                    var regionEmpty        = ClusterSharding.Get(Sys).Start(
                        typeName: "EntityEmpty",
                        entityProps: Props.Create <Entity>(),
                        settings: ClusterShardingSettings.Create(Sys),
                        extractEntityId: extractEntityId,
                        extractShardId: extractShardId,
                        allocationStrategy: allocationStrategy,
                        handOffStopMessage: StopEntity.Instance);

                    Watch(regionEmpty);
                    regionEmpty.Tell(GracefulShutdown.Instance);
                    ExpectTerminated(regionEmpty, TimeSpan.FromSeconds(5));
                }, _config.First);
            });
        }
コード例 #14
0
 private void StartSharding()
 {
     var allocationStrategy = new LeastShardAllocationStrategy(2, 1);
     ClusterSharding.Get(Sys).Start(
         typeName: "Entity",
         entityProps: Props.Create<Entity>(),
         settings: ClusterShardingSettings.Create(Sys),
         idExtractor: extractEntityId,
         shardResolver: extractShardId,
         allocationStrategy: allocationStrategy,
         handOffStopMessage: StopEntity.Instance);
 }
コード例 #15
0
        private Props CoordinatorProps(string typeName, bool rebalanceEntities)
        {
            var allocationStrategy = new LeastShardAllocationStrategy(2, 1);
            var config = ConfigurationFactory.ParseString(string.Format(""));
            var settings = ClusterShardingSettings.Create(config, Sys.Settings.Config.GetConfig("akka.cluster.singleton"));

            return PersistentShardCoordinator.Props(typeName, settings, allocationStrategy);
        }