示例#1
0
        public FailOverLoadBalancingStrategy(EndpointInfo preferredEndpoint, Predicate <EndpointInfo> isAvailable, Func <ILoadBalancingStrategy> fallBackLoadBalancingStrategyFactory = null)
        {
            _preferredEndpoint = preferredEndpoint;
            _isAvailable       = isAvailable;

            _fallBackLoadBalancingStrategy = fallBackLoadBalancingStrategyFactory();
        }
 public LoadBalancingManager(
     IReadonlyInstanceContext instanceContext,
     ILoadBalancingStrategy strategy)
 {
     _instanceContext = instanceContext;
     _strategy        = strategy;
 }
 public TrafficAllocationLoadBalancingStrategy(Func <IEnumerable <EndpointInfo>, IEnumerable <EndpointInfo> > selector, decimal?variation,
                                               ILoadBalancingStrategy backingLoadBalancingStrategy)
 {
     _selector  = selector;
     _variation = (int)((variation ?? 0M) * 100);
     _backingLoadBalancingStrategy = backingLoadBalancingStrategy;
 }
示例#4
0
 public DirectChannel(IApplicationContext context, ILoadBalancingStrategy loadBalancingStrategy, string name, ILogger logger = null)
     : base(context, new UnicastingDispatcher(context), name, logger)
 {
     Dispatcher.LoadBalancingStrategy = loadBalancingStrategy;
     Dispatcher.MaxSubscribers        = int.MaxValue;
     Writer = new DirectChannelWriter(this, logger);
     Reader = new NotSupportedChannelReader();
 }
示例#5
0
 public DirectChannel(IServiceProvider serviceProvider, ILoadBalancingStrategy loadBalancingStrategy, string name, ILogger logger = null)
     : base(serviceProvider, new UnicastingDispatcher(serviceProvider), name, logger)
 {
     Dispatcher.LoadBalancingStrategy = loadBalancingStrategy;
     Dispatcher.MaxSubscribers        = int.MaxValue;
     Writer = new DirectChannelWriter(this, logger);
     Reader = new NotSupportedChannelReader();
 }
示例#6
0
        private static Exception DoStuffWithNodes(ILoadBalancingStrategy strategy, IEnumerable <IRiakNode> nodes)
        {
            var rnd              = new Random();
            var availableNodes   = new Queue <IRiakNode>(nodes);
            var unavailableNodes = new Queue <IRiakNode>();

            try
            {
                for (var i = 0; i < 1000000; ++i)
                {
                    switch (rnd.Next(0, 3))
                    {
                    case 1:
                        strategy.SelectNode();
                        break;

                    case 2:
                        if (unavailableNodes.Count > 0)
                        {
                            var node = unavailableNodes.Dequeue();
                            strategy.AddNode(node);
                            availableNodes.Enqueue(node);
                        }
                        else
                        {
                            --i;
                        }
                        break;

                    default:
                        if (availableNodes.Count > 0)
                        {
                            var node = availableNodes.Dequeue();
                            strategy.RemoveNode(node);
                            unavailableNodes.Enqueue(node);
                        }
                        else
                        {
                            --i;
                        }
                        break;
                    }
                }

                while (availableNodes.Count > 0)
                {
                    strategy.RemoveNode(availableNodes.Dequeue());
                }

                strategy.SelectNode();
            }
            catch (Exception ex)
            {
                return(ex);
            }

            return(null);
        }
        private static Exception DoStuffWithNodes(ILoadBalancingStrategy strategy, IEnumerable<IRiakNode> nodes)
        {
            var rnd = new Random();
            var availableNodes = new Queue<IRiakNode>(nodes);
            var unavailableNodes = new Queue<IRiakNode>();

            try
            {
                for (var i = 0; i < 1000000; ++i)
                {
                    switch (rnd.Next(0, 3))
                    {
                        case 1:
                            strategy.SelectNode();
                            break;
                        case 2:
                            if (unavailableNodes.Count > 0)
                            {
                                var node = unavailableNodes.Dequeue();
                                strategy.AddNode(node);
                                availableNodes.Enqueue(node);
                            }
                            else
                            {
                                --i;
                            }
                            break;
                        default:
                            if (availableNodes.Count > 0)
                            {
                                var node = availableNodes.Dequeue();
                                strategy.RemoveNode(node);
                                unavailableNodes.Enqueue(node);
                            }
                            else
                            {
                                --i;
                            }
                            break;

                    }
                }

                while (availableNodes.Count > 0)
                {
                    strategy.RemoveNode(availableNodes.Dequeue());
                }

                strategy.SelectNode();
            }
            catch (Exception ex)
            {
                return ex;
            }

            return null;
        }
示例#8
0
        // for test only
        internal LoadBalancer(
            IClusterConnectionPool clusterConnPool,
            IRoutingTableManager routingTableManager)
        {
            _clusterConnectionPool = clusterConnPool;
            _routingTableManager   = routingTableManager;
            var config = Config.DefaultConfig;

            _loadBalancingStrategy = CreateLoadBalancingStrategy(config.LoadBalancingStrategy, clusterConnPool, config.Logger);
        }
示例#9
0
        public LoadBalancer(
            IPooledConnectionFactory connectionFactory,
            RoutingSettings routingSettings,
            ConnectionPoolSettings poolSettings,
            IDriverLogger logger)
        {
            _logger = logger;

            _clusterConnectionPool = new ClusterConnectionPool(Enumerable.Empty <Uri>(), connectionFactory, poolSettings, logger);
            _routingTableManager   = new RoutingTableManager(routingSettings, this, logger);
            _loadBalancingStrategy = CreateLoadBalancingStrategy(routingSettings.Strategy, _clusterConnectionPool, _logger);
        }
示例#10
0
        public LoadBalancer(
            IPooledConnectionFactory connectionFactory,
            RoutingSettings routingSettings,
            ConnectionPoolSettings poolSettings,
            ILogger logger)
        {
            _logger = logger;
            var uris = routingSettings.InitialServers;

            _clusterConnectionPool = new ClusterConnectionPool(uris, connectionFactory, poolSettings, logger);
            _routingTableManager   = new RoutingTableManager(routingSettings, this, logger);

            _loadBalancingStrategy = CreateLoadBalancingStrategy(routingSettings.Strategy, _clusterConnectionPool, logger);
        }
示例#11
0
        public LoadBalancer(
            IPooledConnectionFactory connectionFactory,
            RoutingSettings routingSettings,
            ConnectionPoolSettings poolSettings,
            ILogger logger)
        {
            _logger = logger;

            _clusterConnectionPool =
                new ClusterConnectionPool(Enumerable.Empty <Uri>(), connectionFactory, poolSettings, logger);
            _routingTableManager          = new RoutingTableManager(routingSettings, this, logger);
            _loadBalancingStrategy        = CreateLoadBalancingStrategy(_clusterConnectionPool, _logger);
            _initialServerAddressProvider = routingSettings.InitialServerAddressProvider;
        }
        public TaskSchedulerChannel(IApplicationContext context, TaskScheduler executor, ILoadBalancingStrategy loadBalancingStrategy, string name, ILogger logger = null)
            : base(context, new UnicastingDispatcher(context, executor, logger), executor, name, logger)
        {
            if (executor == null)
            {
                throw new ArgumentNullException(nameof(executor));
            }

            Dispatcher.MessageHandlingDecorator = new MessageHandlingDecorator(this);
            Dispatcher.LoadBalancingStrategy    = loadBalancingStrategy;
            Dispatcher.MessageHandlingDecorator = new MessageHandlingDecorator(this);
            Writer = new TaskSchedulerChannelWriter(this, logger);
            Reader = new NotSupportedChannelReader();
        }
 public TaskSchedulerChannel(IApplicationContext context, TaskScheduler executor, ILoadBalancingStrategy loadBalancingStrategy, ILogger logger = null)
     : this(context, executor, loadBalancingStrategy, null, logger)
 {
 }
示例#14
0
 public TaskSchedulerChannel(IServiceProvider serviceProvider, TaskScheduler executor, ILoadBalancingStrategy loadBalancingStrategy, ILogger logger = null)
     : this(serviceProvider, executor, loadBalancingStrategy, null, logger)
 {
 }