Windows系统下模拟Kafka集群参数调优
配置kafka运行环境
kafka的包中已经包含了zookeeper但是我还是喜欢单独下载一个zookeeper下载kafka
https:archive。apache。orgdistkafka2。6。3kafka2。122。6。3。tgz下载zookeeper
https:www。apache。orgdyncloser。luazookeeperzookeeper3。6。3apachezookeeper3。6。3bin。tar。gz配置zookeeper
解压下载的zookeeper安装包
复制三份并修改文件夹的名字(其实可以用三份配置但是我喜欢复制三份)修改点一新建zkData文件夹
在每一份的目录下新建zkData文件夹
修改点二新建myid文件
在每一份的zkData文件夹中新建myid文件,并分别把内容修改为123
修改点三修改配置文件
将conf目录下的zoosample。cfg文件修改为zoo。cfg,并修改文件内容
修改文件内容
第一处dataDir修改为zkData文件夹注意路径要用双反斜杠
第二处端口号因为是在一台机器上跑多个实例所以端口号不能冲突
第三处添加入下内容
server。1localhost:2881:3881server。2localhost:2882:3882server。3localhost:2883:3883
配置参数说明
server。AB:C:D
A是一个数字,表示这个是第几号服务器;
集群模式下配置一个文件myid,这个文件在dataDir目录下,这个文件里面有一个数据就是A的值,Zookeeper启动时读取此文件,拿到里面的数据与zoo。cfg里面的配置信息比较从而判断到底是哪个server。
B是这个服务器的地址;
C是这个服务器Follower与集群中的Leader服务器交换信息的端口;
D是万一集群中的Leader服务器挂了,需要一个端口来重新进行选举,选出一个新的Leader,而这个端口就是用来执行选举时服务器相互通信的端口。
修改后的三个文件内容ThenumberofmillisecondsofeachticktickTime2000ThenumberofticksthattheinitialsynchronizationphasecantakeinitLimit10ThenumberofticksthatcanpassbetweensendingarequestandgettinganacknowledgementsyncLimit5thedirectorywherethesnapshotisstored。donotusetmpforstorage,tmphereisjustexamplesakes。dataDirD:softrepositoryzookeeperapachezookeeper3。6。3bin1zkDatatheportatwhichtheclientswillconnectclientPort2181themaximumnumberofclientconnections。increasethisifyouneedtohandlemoreclientsmaxClientCnxns60Besuretoreadthemaintenancesectionoftheadministratorguidebeforeturningonautopurge。http:zookeeper。apache。orgdoccurrentzookeeperAdmin。htmlscmaintenanceThenumberofsnapshotstoretainindataDirautopurge。snapRetainCount3PurgetaskintervalinhoursSetto0todisableautopurgefeatureautopurge。purgeInterval1MetricsProvidershttps:prometheus。ioMetricsExportermetricsProvider。classNameorg。apache。zookeeper。metrics。prometheus。PrometheusMetricsProvidermetricsProvider。httpPort7000metricsProvider。exportJvmInfotrueserver。1localhost:2881:3881server。2localhost:2882:3882server。3localhost:2883:3883启动zookeeper集群
在cmd中进入每一份的zookeeper文件夹中,执行binzkServer。cmd
配置kafka
在D盘根目录复制解压后的kafka三份修改configserver。properties
broker。id0
log。dirstmpkafkalogs1
zookeeper。connectlocalhost:2181,localhost:2182,localhost:2183kafka
port9091
端口号三份分别为909190929093LicensedtotheApacheSoftwareFoundation(ASF)underoneormorecontributorlicenseagreements。SeetheNOTICEfiledistributedwiththisworkforadditionalinformationregardingcopyrightownership。TheASFlicensesthisfiletoYouundertheApacheLicense,Version2。0(theLicense);youmaynotusethisfileexceptincompliancewiththeLicense。YoumayobtainacopyoftheLicenseathttp:www。apache。orglicensesLICENSE2。0Unlessrequiredbyapplicablelaworagreedtoinwriting,softwaredistributedundertheLicenseisdistributedonanASISBASIS,WITHOUTWARRANTIESORCONDITIONSOFANYKIND,eitherexpressorimplied。SeetheLicenseforthespecificlanguagegoverningpermissionsandlimitationsundertheLicense。seekafka。server。KafkaConfigforadditionaldetailsanddefaultsServerBasicsTheidofthebroker。Thismustbesettoauniqueintegerforeachbroker。broker。id1SocketServerSettingsTheaddressthesocketserverlistenson。Itwillgetthevaluereturnedfromjava。net。InetAddress。getCanonicalHostName()ifnotconfigured。FORMAT:listenerslistenername:hostname:portEXAMPLE:listenersPLAINTEXT:your。host。name:9092listenersPLAINTEXT::9092Hostnameandportthebrokerwilladvertisetoproducersandconsumers。Ifnotset,itusesthevalueforlistenersifconfigured。Otherwise,itwillusethevaluereturnedfromjava。net。InetAddress。getCanonicalHostName()。advertised。listenersPLAINTEXT:your。host。name:9092Mapslistenernamestosecurityprotocols,thedefaultisforthemtobethesame。Seetheconfigdocumentationformoredetailslistener。security。protocol。mapPLAINTEXT:PLAINTEXT,SSL:SSL,SASLPLAINTEXT:SASLPLAINTEXT,SASLSSL:SASLSSLThenumberofthreadsthattheserverusesforreceivingrequestsfromthenetworkandsendingresponsestothenetworknum。network。threads3Thenumberofthreadsthattheserverusesforprocessingrequests,whichmayincludediskIOnum。io。threads8Thesendbuffer(SOSNDBUF)usedbythesocketserversocket。send。buffer。bytes102400Thereceivebuffer(SORCVBUF)usedbythesocketserversocket。receive。buffer。bytes102400Themaximumsizeofarequestthatthesocketserverwillaccept(protectionagainstOOM)socket。request。max。bytes104857600LogBasicsAcommaseparatedlistofdirectoriesunderwhichtostorelogfileslog。dirstmpkafkalogs1Thedefaultnumberoflogpartitionspertopic。Morepartitionsallowgreaterparallelismforconsumption,butthiswillalsoresultinmorefilesacrossthebrokers。num。partitions1Thenumberofthreadsperdatadirectorytobeusedforlogrecoveryatstartupandflushingatshutdown。ThisvalueisrecommendedtobeincreasedforinstallationswithdatadirslocatedinRAIDarray。num。recovery。threads。per。data。dir1InternalTopicSettingsThereplicationfactorforthegroupmetadatainternaltopicsconsumeroffsetsandtransactionstateForanythingotherthandevelopmenttesting,avaluegreaterthan1isrecommendedtoensureavailabilitysuchas3。offsets。topic。replication。factor1transaction。state。log。replication。factor1transaction。state。log。min。isr1LogFlushPolicyMessagesareimmediatelywrittentothefilesystembutbydefaultweonlyfsync()tosynctheOScachelazily。Thefollowingconfigurationscontroltheflushofdatatodisk。Thereareafewimportanttradeoffshere:1。Durability:Unflusheddatamaybelostifyouarenotusingreplication。2。Latency:Verylargeflushintervalsmayleadtolatencyspikeswhentheflushdoesoccurastherewillbealotofdatatoflush。3。Throughput:Theflushisgenerallythemostexpensiveoperation,andasmallflushintervalmayleadtoexcessiveseeks。ThesettingsbelowallowonetoconfiguretheflushpolicytoflushdataafteraperiodoftimeoreveryNmessages(orboth)。Thiscanbedonegloballyandoverriddenonapertopicbasis。Thenumberofmessagestoacceptbeforeforcingaflushofdatatodisklog。flush。interval。messages10000Themaximumamountoftimeamessagecansitinalogbeforeweforceaflushlog。flush。interval。ms1000LogRetentionPolicyThefollowingconfigurationscontrolthedisposaloflogsegments。Thepolicycanbesettodeletesegmentsafteraperiodoftime,orafteragivensizehasaccumulated。Asegmentwillbedeletedwhenevereitherofthesecriteriaaremet。Deletionalwayshappensfromtheendofthelog。Theminimumageofalogfiletobeeligiblefordeletionduetoagelog。retention。hours168Asizebasedretentionpolicyforlogs。Segmentsareprunedfromthelogunlesstheremainingsegmentsdropbelowlog。retention。bytes。Functionsindependentlyoflog。retention。hours。log。retention。bytes1073741824Themaximumsizeofalogsegmentfile。Whenthissizeisreachedanewlogsegmentwillbecreated。log。segment。bytes1073741824Theintervalatwhichlogsegmentsarecheckedtoseeiftheycanbedeletedaccordingtotheretentionpolicieslog。retention。check。interval。ms300000ZookeeperZookeeperconnectionstring(seezookeeperdocsfordetails)。Thisisacommaseparatedhost:portpairs,eachcorrespondingtoazkserver。e。g。127。0。0。1:3000,127。0。0。1:3001,127。0。0。1:3002。Youcanalsoappendanoptionalchrootstringtotheurlstospecifytherootdirectoryforallkafkaznodes。zookeeper。connectlocalhost:2181,localhost:2182,localhost:2183kafkaTimeoutinmsforconnectingtozookeeperzookeeper。connection。timeout。ms18000GroupCoordinatorSettingsThefollowingconfigurationspecifiesthetime,inmilliseconds,thattheGroupCoordinatorwilldelaytheinitialconsumerrebalance。Therebalancewillbefurtherdelayedbythevalueofgroup。initial。rebalance。delay。msasnewmembersjointhegroup,uptoamaximumofmax。poll。interval。ms。Thedefaultvalueforthisis3seconds。Weoverridethisto0hereasitmakesforabetteroutoftheboxexperiencefordevelopmentandtesting。However,inproductionenvironmentsthedefaultvalueof3secondsismoresuitableasthiswillhelptoavoidunnecessary,andpotentiallyexpensive,rebalancesduringapplicationstartup。group。initial。rebalance。delay。ms0port9091启动kafkabinwindowskafkaserverstart。batconfigserver。propertiestopic查看topicbinwindowskafkatopics。batbootstrapserverlocalhost:9091list创建topicbinwindowskafkatopics。batbootstrapserverlocalhost:9091createpartitions1replicationfactor1topichellotest查看topic的详情binwindowskafkatopics。batbootstrapserverlocalhost:9091describetopichellotest修改分区数
注意:分区数只能增加,不能减少binwindowskafkatopics。batbootstrapserverlocalhost:9091altertopichellotestpartitions3删除topicbinwindowskafkatopics。batbootstrapserverlocalhost:9091deletetopichello集群压力测试
用Kafka自带的脚本,对Kafka进行压测。
生产者压测脚本:kafkaproducerperftest。sh
消费者压测脚本:kafkaconsumerperftest。shKafkaProducer压力测试创建一个hellotesttopic,设置为3个分区3个副本binwindowskafkatopics。batbootstrapserverlocalhost:9091createreplicationfactor3partitions3topichellotest测试生产者binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput1producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size16384linger。ms0
recordsize是一条信息有多大,单位是字节,本次测试设置为1k。
numrecords是总共发送多少条信息,本次测试设置为100万条。
throughput是每秒多少条信息,设成1,表示不限流,尽可能快的生产数据,可测出生产者最大吞吐量。
producerprops后面可以配置生产者相关参数,batch。size配置为16k调整batch。size大小
batch。size默认值是16k将batch。size设置为32kbinwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size32768linger。ms0
batch。size默认值是16k。将batch。size设置为4k。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms0调整linger。ms
linger。ms默认是0ms。将linger。ms设置为50ms。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50压缩方式
调整压缩方式默认的压缩方式是none。将compression。type设置为snappy。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50compression。typesnappy
默认的压缩方式是none。将compression。typee设置为zstd。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50compression。typezstd
默认的压缩方式是none。将compression。type设置为gzip。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50compression。typegzip
默认的压缩方式是none。将compression。type设置为lz4binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput10000producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50compression。typelz4调整缓存大小buffer。memory
调整缓存大小默认生产者端缓存大小32m。将buffer。memory设置为64m。binwindowskafkaproducerperftest。battopichellotestrecordsize1024numrecords1000000throughput1producerpropsbootstrap。serverslocalhost:9091,localhost:9092,localhost:9093batch。size4096linger。ms50buffer。memory67108864测试Consumer性能默认情况的吞吐量binwindowskafkaconsumerperftest。batbootstrapserverlocalhost:9091,localhost:9092,localhost:9093topichellotestmessages10000000consumer。configconfigconsumer。propertiestimeout10000
bootstrapserver指定Kafka集群地址
topic指定topic的名称
messages总共要消费的消息个数
调整max。poll。records
一次拉取条数为2000
修改configconsumer。properties文件中的一次拉取条数为2000max。poll。records2000
一次拉取条数为20000
修改configconsumer。properties文件中的一次拉取条数为20000max。poll。records20000
一次拉取条数为200000
修改configconsumer。properties文件中的一次拉取条数为200000max。poll。records200000
可以看到每秒的消息数量已经不会提升了
一次拉取条数为100000
修改configconsumer。properties文件中的一次拉取条数为100000max。poll。records100000
fetch。max。bytes
修改optmodulekafkaconfigconsumer。properties文件中的拉取一批数据大小100mfetch。max。bytes104857600
叛徒张本智和全家叛逃日本,扬言吊打中国乒乓球队,后来怎么样文九月编辑九月2022年7月29日,国际乒联公布了本月23日将要举办WTT支线赛的运动员名单。日本乒乓球协会也公布了,在这次的比赛中,将要上场的运动员和教练的……
别再披头散发了!热不死你!这5款发型才够美够清凉Halo,姐妹们好呀!不知道大家会不会和我一样,一到夏天就热得背夹流汗,很想把长发咔嚓掉。但因为我是大圆脸不敢轻易尝试短发,所以夏天只好把头发扎起来才不会被热……
如果看不惯一个人,请记住这四种回应方式01hr任何一份感情,都是双向奔赴的。你看不惯的人,大概率会看不惯你。投射效应说明,很多人习惯把自己的特点,归于别人身上。用自己的认知去衡量别人,甚至强加于别人。这……
科技鬼才李一男从华为太子爷沦为阶下囚,一把好牌被他打烂为了让华为发展得更好,吸引更多的人才,任正非拿出高薪面向全球,招募天才少年,在高薪的诱惑下,不少人加入。华为不缺优秀人才,但被任正非看好又爬上总裁之位的却不多,这么多年以来也只……
法国希思黎520礼遇季法式奢宠为TA心选5月过半,520即将如约而至。在这浓情蜜意的夏日里,在这大声表白的节日里,情感似乎也呼之欲出,热烈无比。也许不经意就在眉梢、嘴角透露出浓浓的爱意;也许只想给对方最贴心的肌肤守护……
足球报海港有意引进广州队两名归化国脚,包含艾克森直播吧2月24日讯《足球报》消息,上海海港有意引进包括艾克森在内的广州队两名归化国脚球员,以及另一名正值当打之间的广州队国脚。不仅如此,上海海港还将引进徐新,加强中后场的……
碘化镍二维材料中的多铁状态铁电与铁磁同时存在近日,麻省理工学院的物理学家在一种像单层原子一样薄的材料中发现了奇异的多铁性状态。他们的观察结果首次证实了多铁性可以存在于完美的二维材料中。这些发现为开发更小、更快、更高效的数……
50句关于春天的文案春暖花开我负责分享文字,你负责热爱生活!文字的力量第115期01。祝我们好在春天。02。春一暖,花就开了。03。春空烟迷,四山霞飞,谁也夺不去的春天,来临了!……
按摩穴位可以有效的保养身体,推荐这5个穴位,没事揉一揉按摩穴位可以有效保养身体并延年益寿是很多人都听说过的养生小妙招。不过众所周知,人体全身各处分布着的穴位是非常多的,那么想要最大限度的实现延缓衰老和延年益寿效果,到底应当针……
长城脚下年味儿浓延庆最美冬奥城冬季旅游文化节喜迎四方宾朋1月25日,延庆八达岭镇首届冬季旅游文化节精彩继续,石佛寺、石峡、岔道三个村锣鼓喧天,为八方来客呈上长城脚下村民们的节庆盛宴。石佛寺村石佛寺村舞龙队的19名队员,在……
郭艾伦就是这么容易被害干就玩了家里人都认可你决赛MVP评选规则,在这节骨眼上公布,还公布排名,付豪第一艾伦第二。啥意思你们不懂吗?之前就说过了,艾伦需要的是表扬是肯定。官方到底是想中国篮……
容言,容事,容人生活中,一个容字,看似简单,实则寓意深远。海纳百川,有容乃大。容,体现一个人的胸襟气度,一个人的格局度量。生活不是战场,无需一较高下。做自己的事,莫管他人之言论。不论是赞赏支持……