我最近使用 vert.x(基于 java)测试了一个简单的 HTTP 服务器,我对 http 服务器的吞吐量和 api 延迟感到惊讶,它非常快。
http-server 的同一段代码在单线程、无锁和非阻塞的 java 应用程序上运行。性能不到 vert.x one 的 1/3。
我不明白的是,vert.x 优于非响应式 Java 应用程序的核心技术差异是什么?
统计:
测试是使用 Jmeter 完成的。jmeter 和应用程序都在同一台机器上运行——jmeter 消耗 cpu 25-50%,应用程序消耗 cpu 20-30%。所有的测试都运行了 5 分钟。
带有 1 个客户端线程轰炸请求的 Jmeter(每秒:3474 个):

Jmeter 并发 50 个客户端线程轰击请求(每秒 4285 次):

Java问题:
退出同步块会自动执行notifyAll().这是预期的行为吗?
我已经测试了它,看起来像是1.当执行来自同步块时,它会自动执行notifyAll()2.当方法本身同步时,它会在返回时自动通知().(而不是notifyAll())
代码:
public class Test {
public static void main(String[] args) throws InterruptedException {
MyThread lock = new MyThread();
new WatingThread(lock,1).start();
new WatingThread(lock,2).start();
//above tow threads would start and then wait for a lock
lock.start();
}
}
class MyThread extends Thread {
public void run() {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("MyThread is trying to acquire the lock ..");
synchronized (this) {
System.out.println("MyThread has acquired the lock !!");
System.out.println("MyThread is Coming out of …Run Code Online (Sandbox Code Playgroud)