我有一个简单Multithreaded program
的方法,它正在调用一个External API
并从该 API 获取响应。我正在使用RestTemplate
.
问题陈述:-
我试图找出
What is the estimated CPU and IO time for these calls?
我在 Ubuntu 工作。
下面是我的程序-
public class RestLnPTest {
private final static Logger LOG = Logger.getLogger(NokiaLnPTest.class.getName());
private static int noOfThreads = 10;
public static void main(String[] args) {
ExecutorService service = Executors.newFixedThreadPool(noOfThreads);
try {
for (int i = 0; i < 100 * noOfThreads; i++) {
service.submit(new ThreadTask());
}
service.shutdown();
service.awaitTermination(Long.MAX_VALUE, TimeUnit.DAYS);
} catch (InterruptedException e) {
} catch (Exception e) {
} finally {
logHistogramInfo();
}
}
private static void logHistogramInfo() {
System.out.println(ThreadTask.lookupHistogram);
}
}
class ThreadTask implements Runnable {
public static ConcurrentHashMap<Long, AtomicLong> lookupHistogram = new ConcurrentHashMap<Long, AtomicLong>();
private static final String URL = "SOME_URL";
@Override
public void run() {
RestTemplate restTemplate = new RestTemplate();
long start = System.nanoTime();
String result = restTemplate.getForObject(URL, String.class);
long end = System.nanoTime() - start;
final AtomicLong before = lookupHistogram.putIfAbsent(end / 1000000, new AtomicLong(1L));
if (before != null) {
before.incrementAndGet();
}
}
}
我在 Ubuntu 的命令行中运行上述程序 -
java - jar REST.jar
谁能一步一步告诉我如何在 Unix 环境中解决这些调用CPU
?IO time
我只需要粗略估计这些电话。