Skip to content

Instantly share code, notes, and snippets.

@froop
Last active March 26, 2022 07:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save froop/8e0082fe6541842e664dac855986319d to your computer and use it in GitHub Desktop.
Save froop/8e0082fe6541842e664dac855986319d to your computer and use it in GitHub Desktop.
[AWS][EC2][Java] AWSのDNSクォータをテスト
// Command: java -Dsun.net.inetaddr.ttl=0 TestDnsQuotaByInetAddress 172.30.3.11
// Metric: ethtool -S eth0 | grep linklocal_allowance_exceeded
public class TestDnsQuotaByInetAddress {
private static final int TRIALS = 10_000;
private static final int THREADS = 1_024;
private static final int LOG_THRESHOLD = 1_000;
public static void main(String[] args) throws InterruptedException, ExecutionException {
final String host = args[0];
final ExecutorService executor = Executors.newFixedThreadPool(THREADS);
final Object mutex = new Object();
final List<Future<?>> futures = new ArrayList<>();
long totalStartTime = System.currentTimeMillis();
for (int i = 0; i < TRIALS; i++) {
futures.add(executor.submit(() -> {
try {
long startTime = System.currentTimeMillis();
InetAddress address = InetAddress.getByName(host);
long initTime = System.currentTimeMillis();
String hostAddress = address.getHostAddress();
long addressTime = System.currentTimeMillis();
String hostName = address.getHostName();
long nameTime = System.currentTimeMillis();
if (nameTime - startTime >= LOG_THRESHOLD) {
synchronized (mutex) {
System.out.println(String.format("%06d %05d %05d %05d %s %s",
System.currentTimeMillis() - totalStartTime, initTime - startTime, addressTime - initTime,
nameTime - addressTime, hostAddress, hostName));
}
}
return null;
} catch (Throwable e) {
e.printStackTrace();
System.exit(-1);
return null;
}
}));
}
for (Future<?> res : futures) {
res.get();
}
System.out.println(String.format("total: %d ms", System.currentTimeMillis() - totalStartTime));
executor.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment