실패한 Hama 개선 경험
@Override
public GraphJobMessage poll() {
if (mapMessages.size() > 0) {
return mapMessages.poll();
} else {
if (storage.size() > 0 && it.hasNext()) {
GraphJobMessage m = it.next();
it.remove();
return m;
} else {
return null;
}
}
}
이론적으로 읽으면서 삭제하는 것은 효율이 비교적 낮기 때문에 한 번에 읽고 모두 삭제하는 것이 낫다. 테스트 코드는 다음과 같다.
package concurrencyTest;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrencyReadTest {
/**
* @param args
*/
public static void main(String[] args) {
ConcurrentHashMap map = new ConcurrentHashMap() ;
for(int i=0;i<1000000 ; i++)
map.put(i, i+111111) ;
long start = System.currentTimeMillis() ;
Thread t1 = new Thread(new Worker(map)) ;
t1.start();
try {
t1.join() ;
} catch (InterruptedException e) {
e.printStackTrace();
}
// map.clear() ;
System.out.println("Read last : " + (System.currentTimeMillis() - start) + " ms");
}
}
class Worker implements Runnable {
ConcurrentHashMap sharemap ;
int num = 0 ;
public Worker(ConcurrentHashMap map) {
sharemap = map ;
}
@Override
public void run() {
it = sharemap.values().iterator();
Integer i = poll();
while(i!=null) {
i = poll() ;
num++ ;
}
System.out.println(Thread.currentThread().getName() + " poll " + num + " elements! ShareMap size: " + sharemap.size() );
}
Iterator it;
public Integer poll() {
if (sharemap.size() > 0 && it!=null && it.hasNext()) {
Integer m = it.next();
it.remove();
return m;
} else {
return null;
}
}
}
테스트 3회 결과:187172,172
코드를 다음과 같이 수정합니다.
package concurrencyTest;
import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap;
public class ConcurrencyReadTest {
/**
* @param args
*/
public static void main(String[] args) {
ConcurrentHashMap map = new ConcurrentHashMap() ;
for(int i=0;i<1000000 ; i++)
map.put(i, i+111111) ;
long start = System.currentTimeMillis() ;
Thread t1 = new Thread(new Worker(map)) ;
// Thread t2 = new Thread(new Worker(map)) ;
t1.start();
// t2.start();
try {
t1.join() ;
// t2.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
map.clear() ;
System.out.println("Read last : " + (System.currentTimeMillis() - start) + " ms");
}
}
class Worker implements Runnable {
ConcurrentHashMap sharemap ;
int num = 0 ;
public Worker(ConcurrentHashMap map) {
sharemap = map ;
}
@Override
public void run() {
it = sharemap.values().iterator();
Integer i = poll();
while(i!=null) {
i = poll() ;
num++ ;
}
System.out.println(Thread.currentThread().getName() + " poll " + num + " elements! ShareMap size: " + sharemap.size() );
}
Iterator it;
public Integer poll() {
if (sharemap.size() > 0 && it!=null && it.hasNext()) {
Integer m = it.next();
// it.remove();
return m;
} else {
return null;
}
}
}
테스트 3회 결과:140124,140
확실히 빠르다는 것을 알 수 있다.
그러나 이러한 개선 사항을 Hama에 적용하면 전체 계산 시간이 집계됩니다.
새 버전:
16/09/24 16:20:20 INFO graph.GraphJobRunner: totalBroasdCastTime: 1793 totalSyncTime: 9219 totalLoopingTime: 13059 16/09/24 16:21:30 INFO graph.GraphJobRunner: totalBroasdCastTime: 2008 totalSyncTime: 9699 totalLoopingTime: 12834 16/09/24 16:22:47 INFO graph.GraphJobRunner: totalBroasdCastTime: 1909 totalSyncTime: 9192 totalLoopingTime: 12634
옛날 판
16/09/24 16:32:22 INFO graph.GraphJobRunner: totalBroasdCastTime: 1993 totalSyncTime: 8351 totalLoopingTime: 13387 16/09/24 16:34:28 INFO graph.GraphJobRunner: totalBroasdCastTime: 1582 totalSyncTime: 8635 totalLoopingTime: 12827 16/09/24 16:35:39 INFO graph.GraphJobRunner: totalBroasdCastTime: 1679 totalSyncTime: 8543 totalLoopingTime: 12836
그러나 마지막 시간의 총, 아니면 오래된 버전이 좀 빠른지 이유를 알 수 없다. 미리 삭제해서 사용 가능한 메모리가 커지고 성능이 향상되었는지 추측할 수 있다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.