Tuesday, 15 September 2015

java - Balancing multiple queues -



java - Balancing multiple queues -

i suspect easy i’m unsure if there’s naïve way of doing in java. here’s problem, have 2 scripts processing info , both have same inputs/outputs except 1 written single cpu , other gpus. work comes queue server , i’m trying write programme sends info either cpu or gpu script depending on 1 free.

i not understand how this.

i know executorservice can specify how many threads want maintain running not sure how balance between 2 different ones. have 2 gpu’s , 8 cpu cores on scheme , thought have threadexecutorservice maintain 2 gpu , 8 cpu processes running unsure how balance between them since gpu done lot quicker cpu tasks.

any suggestions on how approach this? should create 2 queues , maintain pooling them see 1 less busy? or there way set work units(all same) 1 queue , have gpu or cpu process take same queue free?

update: clarify. cpu/gpu programs outside scope of programme i'm making, scripts phone call via 2 different method. guess simplified version of i'm asking if 2 methods can take work same queue?

can 2 methods take work same queue?

yes, should utilize blockingqueue save synchronization heartache.

basically, 1 alternative have producer places tasks queue via blockingqueue.offer. design cpu/gpu threads phone call blockingqueue.take , perform work on whatever receive.

for example:

main (...) { blockingqueue<task> queue = new linkedblockingqueue<>(); (int i=0;i<cpus;i++) { new cputhread(queue).start(); } (int i=0;i<gpus;i++) { new gputhread(queue).start(); } (/*all data*/) { queue.offer(task); } } class cputhread { public void run() { while(/*some condition*/) { task task = queue.take(); //do task work } } } //etc...

java multithreading

No comments:

Post a Comment