06-请求超时

Catalogue
  1. 1. 参考资料

该任务演示,怎么设置请求超时。

使用bookinfo项目,初始化所有都使用v1版本,配置如下:

1
kubectl apply -f samples/bookinfo/networking/virtual-service-all-v1.yaml
  1. 配置路由请求到reviews-v2, 该版本会调用ratings服务
1
2
3
4
5
6
7
8
9
10
11
12
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v2
  1. 为ratings服务添加一个2秒的延时
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: ratings
spec:
hosts:
- ratings
http:
- fault:
delay:
percent: 100
fixedDelay: 2s
route:
- destination:
host: ratings
subset: v1
  1. 访问测试

访问:http://bookinfo.example.com/productpage

多次刷新,每次都会大约2秒延时响应。

  1. 为reviews服务添加一个0.5秒延时
1
2
3
4
5
6
7
8
9
10
11
12
13
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: reviews
spec:
hosts:
- reviews
http:
- route:
- destination:
host: reviews
subset: v2
timeout: 0.5s
  1. 访问测试

访问:http://bookinfo.example.com/productpage

多次刷新,每次都会大约1秒返回,且显示reviews 不可用。

1秒的原因是,0.5秒延时+1次重试。

参考资料