0
我寫了一個矩陣乘法算法,它使用並行集合來加速乘法。Akka - 負載平衡和充分利用處理器
,過程大概是:
(0 until M1_ROWS).grouped(PARTITION_ROWS).toList.par.map(i =>
singleThreadedMultiplicationFAST(i.toArray.map(m1(_)), m2)
).reduce(_++_)
現在我想這樣做在阿卡,所以我所做的是:
val multiplyer = actorOf[Pool]
multiplyer start
val futures = (0 until M1_ROWS).grouped(PARTITION_ROWS).map(i =>
multiplyer ? MultiplyMatrix(i.toArray.map(m1(_)), m2)
)
futures.map(_.get match { case res :Array[Array[Double]] => res }).reduce(_++_)
class Multiplyer extends akka.actor.Actor{
protected def receive = {
case MultiplyMatrix(m1, m2) => self reply singleThreadedMultiplicationFAST (m1,m2)
}
}
class Pool extends Actor with DefaultActorPool
with FixedCapacityStrategy with RoundRobinSelector {
def receive = _route
def partialFill = false
def selectionCount = 1
def instance = actorOf[Multiplyer]
def limit = 32 // I tried 256 with no effect either
}
原來,這個算法基於actor版本在我的i7 sandybridge上僅使用 200%,而平行收集版本是 ,使用600%的處理器,速度提高4-5倍。 我想這可能是調度員,並試圖此:
self.dispatcher = Dispatchers.newThreadBasedDispatcher(self, mailboxCapacity = 100)
,這(我分享者之間的一個):
val messageDispatcher = Dispatchers.newExecutorBasedEventDrivenDispatcher("d1")
.withNewBoundedThrea dPoolWithLinkedBlockingQueueWithUnboundedCapacity(100)
.setCorePoolSize(16)
.setMaxPoolSize(128)
.setKeepAliveTimeInMillis(60000).build
但我沒有看到任何改變。該算法仍然只有200%的處理器使用率,並且該算法比平行收集版本 慢了4-5倍。
我相信我在做一些愚蠢的,所以請幫助!:)