在 Java 中使用 Dubbo 处理高并发,通常不是“某一个配置”能解决的,而是架构 + 配置 + 代码多方面的组合优化。下面按常见且实用的角度给你系统讲一下。
Dubbo provider 端默认使用 固定线程池,高并发下必须调优。
<dubbo:protocol name="dubbo" port="20880"
threadpool="fixed"
threads="200"
queues="0"/>
常用线程池类型:
fixed:固定线程(常用)cached:弹性线程(适合短任务)limited:线程数受限经验值:
⚠️ queues=0 表示不排队,直接拒绝,避免雪崩
<dubbo:service interface="com.xxx.UserService"
executions="100"/>
表示:每秒最多 100 次调用
<dubbo:reference interface="com.xxx.UserService"
actives="10"/>
表示:最多 10 个并发请求
<dubbo:reference timeout="1000" retries="0"/>
高并发原则:
<dubbo:reference loadbalance="leastactive"/>
常用:
random(默认)roundrobinleastactive(推荐高并发)consistenthash<dubbo:reference cluster="failfast"/>
高并发推荐:
failoverfailfastfailsafe<dubbo:reference connections="10"/>
CompletableFuture<User> future = userService.getUserAsync(id);
或用:
<dubbo:reference async="true"/>
| 场景 | 方案 |
|---|---|
| 缓存 | Redis |
| 削峰 | MQ(Kafka / RocketMQ) |
| 限流 | Sentinel |
| 降级 | Sentinel / Hystrix |
| 监控 | Dubbo Admin + Prometheus |
Gateway
↓
Dubbo Consumer
↓
Sentinel(限流/降级)
↓
Dubbo Provider(多线程)
↓
Redis / DB / MQ
❌ 默认线程数太小
❌ 无超时
❌ 无限流
❌ 同步阻塞调用
❌ Provider 单节点
如果你愿意,我可以:
你可以说下:当前 QPS、服务数量、是否用 Spring Boot。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。