【发布时间】:2025-12-01 11:30:01
【问题描述】:
我有一个简单的 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 ?我只需要粗略估计这些调用。
【问题讨论】:
-
你可以在这个帖子*.com/questions/3017162/…找到
cpu use
标签: java rest unix io cpu-time