聊聊Http连接池1ApacheHttpClient2OKHttp33reactornettyHtt

4、zuul/feign/springcloudgateway中采用的连接池

简化后的系统架构图如下:

经统计,所有慢接口均为5703接口,所有慢接口都属于operation-service服务,其他服务正常。

1、哪个服务出现问题了?网关zuul还是operation-service服务?

查看skywalking监控,发现operation-service服务仅耗时12ms,大概率是zuul的问题。

2、由于1s左右就恢复了,猜测是否当时正好进行了FullGC?

通过jstat-gc查看,6次fullgc共耗时0.775s,平均每次耗时不到200ms。另外,查看日志,发现在55~56s期间,还有不少请求都是20ms以内就返回了,基本可以确定和fullgc无关。

3、猜测是否和连接池有关?

zuul1.0默认通过ribbon进行负载均衡。查看ribbon的配置,除了ribbon.ReadTimeout修改为10s以外,其余都是默认配置。

publicclassDefaultClientConfigImplimplementsIClientConfig{//每个路由最大连接数50publicstaticfinalintDEFAULT_MAX_CONNECTIONS_PER_HOST=50;//最大连接数200publicstaticfinalintDEFAULT_MAX_TOTAL_CONNECTIONS=200;}查看日志,发现每秒上百次请求,其中有80%都是operation-service服务的。这么看,只要operation-service服务有接口稍微慢一些,默认的50个连接很可能就不够了。可以调大连接数:

一般有以下常用参数:

**最大连接数:**限制连接池中的最大连接,不能配置的太小,否则高并发时容易阻塞。

**单路由最大连接数:**一般用在网关中,微服务架构体系下,网关可能需要连接几十个微服务,限制单路由最大连接数,某个服务发生异常时,可以尽量不影响其他服务。

**最大空闲连接数:**如果连接池中的连接都不再使用,也是一种浪费,可以清理掉部分连接。

zuul1.0默认采用的是HttpClient,一般通过PoolingHttpClientConnectionManager创建。

接下来看下zuul中是如何配置这个连接池的。

ribbon:MaxConnectionsPerHost:200MaxTotalConnections:500可以通过debug确认:

定时任务处理过期连接:

publicConnectionPool(intmaxIdleConnections,longkeepAliveDuration,TimeUnittimeUnit){ this.delegate=newRealConnectionPool(maxIdleConnections,keepAliveDuration,timeUnit);}maxIdleConnections:最大空闲连接数;

连接池可选,如果需要采用ApacheHttpClient的话,直接引入依赖即可。

引入依赖:

publicclassHttpClientProperties{publicstaticclassPool{ /**TypeofpoolforHttpClienttouse,defaultstoELASTIC.*/ privatePoolTypetype=PoolType.ELASTIC; /** *OnlyfortypeFIXED,themaximumnumberofconnectionsbeforestartingpending *acquisitiononexistingones. */ privateIntegermaxConnections=ConnectionProvider.DEFAULT_POOL_MAX_CONNECTIONS; /** *Timeinmillisafterwhichthechannelwillbeclosed.IfNULL,thereisnomax *idletime. */ privateDurationmaxIdleTime=null; /** *Durationafterwhichthechannelwillbeclosed.IfNULL,thereisnomaxlife *time. */ privateDurationmaxLifeTime=null;}}通过HttpClientFactory创建HttpClient,连接池策略由ConnectionProvider配置。

Feign同时提供了对ApacheHttpClient、OKHttpClient连接池的支持,可自由选择。

比如最大连接数,应该配置多少合理呢?上线前谁也不知道接口会有多大并发,保险起见最好配置大些。单路由最大连接数,这个要根据每个微服务的访问流量来配置,怎么确定?

THE END
1.class是什么意思翻译教育易成财富class 是一个非常常见的英语单词,它有多种含义,具体如下:作为名词班级;班;年级例如:I& 39;m in Class 2, Grade 3 (我在三年级http://www.yichengcf.com/edu/202412/t20241206_43250.shtml
2.onclassinclass区别答案解析 查看更多优质解析 解答一 举报 不是on class指在种类上 on-class teaching才是指课堂教学in class指在课堂上;上课中另外补充:practice on the class随堂练习discuss on the class随堂小议 解析看不懂?免费查看同类题视频解析查看解答 相似问题 in class和 on class都是课上的意思吗?有什么区别? 上课在https://www.zybang.com/question/c1616281874539a5017539ef81cc6ca6.html
3.人教版英语七年级下册知识点So in my opinion, the best way to go to school is on foot. What about you? Unit4 Don’t eat in class. ◆短语归纳 1. on time 准时,按时 2. listen to… 听…… 3. in class 在课上 4. be late for 做……迟到 5. have to 不得不 https://www.diyifanwen.com/fanwen/shishiredian/5526289.html
4.inclass与onclass的区别1. on class指在种类上。2. on-class teaching才是指课堂教学。3. in class指在课堂上;上课中。4https://wenwen.soso.com/z/q656900570.htm
5.inclass和onclass的区别吧友互助吧in class和on class的区别为:* **含义不同。**on class指在种类上,而in class指在课堂上。* **用法不同。**in class,当其意为“在课堂上;上课中”时,其通常用于表示地点,符合“介词+抽象名词”的结构。而on class多出现在短语on-class teaching中,表示“课堂教学”。 2楼2023-09-01 18:47 回复 https://tieba.baidu.com/p/8580342680
6.语法专区介词inonat的使用规则孩子总是分不清介词at、on、in的用法 今天,快来跟小编一起来学习一下吧! 一、in 介词in是非常常用的一个介词, 它的原意是在……里面, 它既可以表示实际的方位,也可以表示抽象概念。 例 The cat is in the box.小猫在盒子里。 There is a hero in evhttps://mp.weixin.qq.com/s?__biz=MzA4OTEzMTYzNg==&mid=2650866908&idx=1&sn=40735b9db9cfcbfe9cb54dcaedcfe979&chksm=8bea3bc7bc9db2d19cd838c3e41f49aa8f7b47df11a05bfb903a41c7104520eb87f48ea49c2c&scene=27
7.onclass是什么意思,在课上?等于inclass?答案解析 查看更多优质解析 解答一 举报 on class 在种类上,在课堂上in class 在课堂上;上课中,在上课,on class 和 in class :在课堂上,才是相等的 解析看不懂?免费查看同类题视频解析查看解答 相似问题 in class和 on class都是课上的意思吗?有什么区别? 在课上,在上课的时候 是用in the class还是onhttps://qb.zuoyebang.com/xfe-question/question/8f2866480381845d37805d4b893a72d0.html
8.小升初人教版英语试卷及答案(通用6套)3. A. On B. At C. In 4. A. breakfast B. lunch C. dinner 5. A. a B. the C. / 三、阅读理解 17.阅读John的'日程表,选择正确答案。 Monday 10:30—11a.m visit Uncle Peter in hospital Tuesday 2—4p.m have a swimming class https://www.yjbys.com/edu/xiaoshengchu/122777.html
9.中考考点:冠词的用法专题精讲及同步练习(3)介词词组:at home在家;in surprise惊奇地;at noon在中午;on foot步行;at night在晚上;on duty值日;at work在工作;on time准时;for example例如;in class在上课;on show展览;in bed在床上 (4)go短语:go home回家;go to bed上床睡觉;go to school去上学;go to work去上班;go shopping/swimming/boatinghttp://www.zhjtjyw.com/m/blog/list?b_id=188813&u_id=169
10.初三英语知识点总结初三英语19.later on随后 20.in class在课堂上 21.laught at 嘲笑 22.take notes 记笔记 23.enjoy doing 喜欢干… 24.write down 写下,记下 25.look up (v + adv) 查找,查询 26.native speakers 说本族话的人 27.make up 编造,虚构,化妆,打扮 http://m.hujiang.com/zx/p251900/
11.FirstClassversusSecondClassonEuropeanTrainsTrainlineWant to learn more about First and Second Class train tickets in Europe? Read our guide for more info and book First Class or Second Class tickets online with us.https://www.thetrainline.com/trains/europe/first-and-second-class
12.IaminClassTwo,GradeOneonNo.8MiddleSchool的翻译是:我Li Lei now is a third day student, his in recent years life has had the very big change.He with first skips classes frequently, attends class is late frequently, likes the computer game, has clashes of opinion with schoolmate, fights.In teacher and schoolmate in the eye he is a questionhttp://eyu.zaixian-fanyi.com/fan_yi_1632186
13.inaton的地点用法in at on的地点用法 at作介词是“在”的意思,表示存在或出现的地点、场所、位置、空间,一般表示小地点;in作介词是“在……里面、具有……特性”,一般表示大地点;on作介词是“在……之上,向,朝”表示处于一个或大或小的平面上,on也可以和星球连用。http://m.chusan.com/zhongkao/90619.html
14.Englishgamesinclass6.What's on the top? Let's play a game. Review the words. What's this? What's this?两个单词交替往上最后举过头顶放平What'son the top? 7.Minesweeper (1)Let'splay a game. Review the words. What's this? Put the card in a line ,put thebomb above a picture .Now, I pat thehttps://sz.zjer.cn/index.php?r=portal/content/view&id=3092031
15.初一英语重点句子汇总精选11. Don't eat in class. 在课堂上不准吃东西。 12. Don't arrive late for class, you must be on time. 不准上课迟到,务必守时。 13. Don’t run is the hallways. 不准在走廊内乱跑。 14. Don’t eat in the classroom. You must in the dining hall.不准在教室里吃东西,务必在餐厅里吃东https://www.ruiwen.com/juzi/yingyu/69566.html
16.MyQuestionsonShadowsinParadise(天堂孤影)影评which we’ve read last semester. Both of the film and the article are talking about the stories of the same class, the lower working class, which has nothing glamorous but unique. As we all know, paradise represents a bright and joyful image, so how come there are some shadows in paradihttps://movie.douban.com/review/2055877/
17.具体日期前用in还是on具体日期前用“on”,介词“on”表示具体某一天,如星期几,节日以及具体某一天的早中晚。比如“onMonday”,在星期一。例句:“WehaveEnglishclassonMonday.”,我们在周一https://m.edu.iask.sina.com.cn/jy/22Ggqdi4Kfq.html
18.SesameScript:ClassisinSessionMicrosoftLearnA class is similar in that it gives you a framework to work from. Let’s see what a Kitchen class would look like. Obviously you can’t fry an egg on your kitchen plan, you need to actually build the kitchen and put the stove in to do that. In the same way you can’t really https://technet.microsoft.com/en-us/library/ee176992.aspx
19.Digitaldistractioninclassisontherise,studysaysCollege students spend more class time than ever playing with their smartphones and other digital devices, according to a new University of Nebraska-Lincoln study. Students check their phones and other digital devices in class more than 11 times a day on average, according to the survey of 675https://medicalxpress.com/news/2016-01-digital-distraction-class.html
20.《Oninit日期用法口诀》at noon,at night,at the weekend,at在某时某刻前1。 - 年月周前要用in,日子前面却不行;遇到几号要用on,上午下午又是in;要说某日上下午,用on换in才能行;午夜黄昏须用at,黎明用它也不错;at也用在分钟前,说“差”可要用上to;说“过”只可使用past,多说多练牢牢记2。https://www.meipian.cn/4r51rncj
21.SCR44ofpollenSCR/SP11 encodes the male determinant of recognition specificity of self-incompatibility (SI) in Brassica species and is sporophytically expressed in the anther tapetum. Based on dominance relationships in pollen and nucleotide sequence similarity, the Shttps://www.nature.com/articles/s41438-018-0103-5
22.EssayWriting:EssayonsocialclassinthegreatgatsbytopEssay on social class in the great gatsbyThe findings showed that the adverbials for example that used similar variables to classify particulars are gatsby the essay on social class in great plausible. The following excerpt from a dogmatic assertion that suitable modelling activities, and who is menhttps://indiana.internexus.edu/courses/essay-on-social-class-in-the-great-gatsby/52/
23.高考英语复习优秀教案七篇1) Be confident of standing on the stage and speak clearly and spontaneously. 2) Encourage students to speak in the class with different kind of techniques. 教学重难点 Focal points: By the end of the class, students are able to: http://www.jiaoyubaba.com/gaozhong/34403.html