简体   繁体   English

奥尔良的工作分配

[英]Work distribution in Orleans

In Microsoft Orleans I am trying to implement something like a list of available work using the code below: 在Microsoft Orleans中,我尝试使用以下代码来实现类似可用工作列表的内容:

        public Task<WorkResponse> PerformWork(WorkRequest request)
    {
        Console.WriteLine("Performing work for id: {0}", request.Param1);
        Thread.Sleep(TimeSpan.FromSeconds(10));                       

        var result = Task.FromResult(new WorkResponse(request.Param1, request.Param2, request.Param3));
        Console.WriteLine("Completed work for id: {0}", request.Param1);

        return result;
    }

This works however if I start a number of tasks using code like this things don't behave properly. 但是,如果我使用诸如此类的代码启动许多任务,则这种方法将无法正常工作。

                _work
                .ToList()
                .AsParallel()                    
                .ForAll(x =>
                {        
                    Console.WriteLine("Requesting work for id: {0}", x.Key);
                    var worker = GrainFactory.GetGrain<IWork>(x.Key);
                    var response = worker.PerformWork(x.Value);

                    Console.WriteLine("Response for work id: {0}", x.Key);
                });

This works however if another node joins the cluster that work seems to never move to the new node. 但是,如果另一个节点加入群集,则该工作似乎永远不会移动到新节点,因此可以正常工作。 Only newly scheduled work is ever processed on that new node. 在该新节点上只会处理新安排的工作。

It also seems that if there is a bunch of this extra work in the Orleans Queue then new nodes get stuck joining the cluster. 看来,如果在奥尔良队列中还有很多额外的工作,那么新节点将卡在集群中。

Orleans uses a fixed number of worker threads to minimize the overhead of context switching and threads. Orleans使用固定数量的工作线程来最大程度地减少上下文切换和线程的开销。 Calling Thread.Sleep() is going to cause trouble, since the workers will be too busy sleeping to pull new work from the queue. 调用Thread.Sleep()会造成麻烦,因为工作人员将太忙于睡眠而无法从队列中提取新工作。

What happens when you avoid Thread.Sleep(...) and use await Task.Delay(...) instead. 当您避免Thread.Sleep(...)并使用await Task.Delay(...)时会发生什么。

The membership algorithm which Orleans uses requires that silos be responsive: slow silos are indistinguishable from dead silos. 奥尔良使用的隶属度算法要求筒仓必须具有响应能力:缓慢的筒仓与死筒仓是无法区分的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM