0
点赞
收藏
分享

微信扫一扫

学习Angular的编程之旅

独兜曲 2023-06-16 阅读 57

相关 

   雪崩 - 如何重试 - sla和重试风暴的双保证_个人渣记录仅为自己搜索用的博客-CSDN博客

接口耗时公式

   耗时= cpu时间 + io时间

线程池数量

最佳数目 =  1s / 平均cpu时间 * 内核数. 

最大平均cpu时间 = 接口耗时- all外部io时间. 结合gc , linux本身其他线程, 只会还少点.

当前我们是没有统计的.

小实验:

     如附录, 200次, 2000次调用 11毫秒,  20ms 基本是50个线程池 * 8核 = 400 . 

线程队列的作用

  线程队列的好处就是 线程数目满了之后, 放到队列里 .

  坏处是 堆积, 堆积的时间也会提现在api接口耗时中. 

修正后的接口耗时

      耗时 = 队列等待时间 + cpu时间 + io时间

    注意 :  队列等待时间 不是 真正执行时间.

突破资源边界后的稳定性问题

      队列等待时间 =  队列数 * 接口真正执行平均耗时 ( cpu时间 + io时间 )  > 上游超时时间.

      继续重试, 队列继续填满 ,队列永远满.

附录: 

     200次方法调用.

public void test(){
StopWatch stopWatch=new StopWatch("t1");
stopWatch.start("initStopWatch");
stopWatch.stop();

stopWatch.start("newHashMap");
Map<String,Object> map= Maps.newHashMap();

int count=200;
for (int i = 0; i < 200; i++) {
put(map, i);
}
stopWatch.stop();
stopWatch.start("initJson");
Map<String,Object> map2= Maps.newHashMap();

map2.put("1",1);
String value1= JSON.toJSONString(map2);
String nu1=value1;
stopWatch.stop();

stopWatch.start("json");
String value= JSON.toJSONString(map);
String nu=value;
stopWatch.stop();


System.out.println("count="+count+",costTimeMs="+stopWatch.getTotalTimeMillis()+",cost="+stopWatch.prettyPrint());

}

private void put(Map<String,Object> map, int i) {
map.put("i"+i,1+i);
}

200次方法调用 8毫秒

2000次调用 11毫秒

2万次调用 36毫秒

举报

相关推荐

0 条评论