mirror of
https://github.com/doocs/advanced-java.git
synced 2025-03-12 09:50:11 +08:00
docs(high-availability): update hystrix
更新 Hystrix 多个文件描述信息
This commit is contained in:
parent
19cfea0f05
commit
84bbe0b597
@ -42,6 +42,7 @@ public class BrandCache {
|
||||
|
||||
/**
|
||||
* brandId 获取 brandName
|
||||
*
|
||||
* @param brandId 品牌id
|
||||
* @return 品牌名
|
||||
*/
|
||||
|
@ -40,9 +40,9 @@ HystrixObservableCommand hystrixObservableCommand = new HystrixObservableCommand
|
||||
- toObservable():返回一个 Observable 对象,如果我们订阅这个对象,就会执行 command 并且获取返回结果。
|
||||
|
||||
```java
|
||||
K value = hystrixCommand.execute();
|
||||
Future<K> fValue = hystrixCommand.queue();
|
||||
Observable<K> oValue = hystrixObservableCommand.observe();
|
||||
K value = hystrixCommand.execute();
|
||||
Future<K> fValue = hystrixCommand.queue();
|
||||
Observable<K> oValue = hystrixObservableCommand.observe();
|
||||
Observable<K> toOValue = hystrixObservableCommand.toObservable();
|
||||
```
|
||||
|
||||
@ -106,7 +106,8 @@ observable.subscribe(new Observer<ProductInfo>() {
|
||||
|
||||
/**
|
||||
* 获取完一条数据,就回调一次这个方法
|
||||
* @param productInfo
|
||||
*
|
||||
* @param productInfo 商品信息
|
||||
*/
|
||||
@Override
|
||||
public void onNext(ProductInfo productInfo) {
|
||||
|
@ -58,8 +58,8 @@ semaphore 技术可以用来限流和削峰,但是不能用来对调研延迟
|
||||
|
||||
在 command 内部,写死代码,做一个 sleep,比如 sleep 3s。
|
||||
|
||||
- withCoreSize:设置线程池大小
|
||||
- withMaxQueueSize:设置等待队列大小
|
||||
- withCoreSize:设置线程池大小。
|
||||
- withMaxQueueSize:设置等待队列大小。
|
||||
- withQueueSizeRejectionThreshold:这个与 withMaxQueueSize 配合使用,等待队列的大小,取得是这两个参数的较小值。
|
||||
|
||||
如果只设置了线程池大小,另外两个 queue 相关参数没有设置的话,等待队列是处于关闭的状态。
|
||||
|
@ -1,5 +1,4 @@
|
||||
## 基于 Hystrix 线程池技术实现资源隔离
|
||||
|
||||
上一讲提到,如果从 Nginx 开始,缓存都失效了,Nginx 会直接通过缓存服务调用商品服务获取最新商品数据(我们基于电商项目做个讨论),有可能出现调用延时而把缓存服务资源耗尽的情况。这里,我们就来说说,怎么通过 Hystrix 线程池技术实现资源隔离。
|
||||
|
||||
资源隔离,就是说,你如果要把对某一个依赖服务的所有调用请求,全部隔离在同一份资源池内,不会去用其它资源了,这就叫资源隔离。哪怕对这个依赖服务,比如说商品服务,现在同时发起的调用量已经到了 1000,但是线程池内就 10 个线程,最多就只会用这 10 个线程去执行,不会说,对商品服务的请求,因为接口调用延时,将 tomcat 内部所有的线程资源全部耗尽。
|
||||
|
Loading…
Reference in New Issue
Block a user