专栏名称: 高可用架构
高可用架构公众号。
目录
相关文章推荐
字节跳动技术团队  ·  基于LLM的AI应急:多模态信息智能化分析整 ... ·  15 小时前  
字节跳动技术团队  ·  远程访问代理+内网穿透:火山引擎边缘网关助力 ... ·  昨天  
字节跳动技术团队  ·  稀土掘金 x Trae ... ·  昨天  
51好读  ›  专栏  ›  高可用架构

一行代码改进:Logtail的多行日志采集性能提升7倍的奥秘

高可用架构  · 公众号  · 架构  · 2024-12-16 11:38

正文

请到「今天看啥」查看全文


void BM_Regex_Match ( int batchSize) { std :: string buffer = "cnt:" ; std :: string regStr = "cnt.*" ; boost:: regex reg (regStr) ; std :: ofstream outFile ( "BM_Regex_Match.txt" , std ::ios::trunc) ; outFile.close();
for ( int i = 0 ; i < 1000 ; i++) { std :: ofstream outFile ( "BM_Regex_Match.txt" , std ::ios::app) ; buffer += "a" ;
int count = 0 ; uint64_t durationTime = 0 ; for ( int i = 0 ; i < batchSize; i++) { count++; uint64_t startTime = GetCurrentTimeInMicroSeconds(); if (!boost::regex_match(buffer, reg)) { std :: cout << "error" << std :: endl ; } durationTime += GetCurrentTimeInMicroSeconds() - startTime; } outFile << i << '\t' << "durationTime: " << durationTime << std :: endl ; outFile << i << '\t' << "process: " << formatSize(buffer.size() * ( uint64_t )count * 1000000 / durationTime) << std :: endl ; outFile.close(); } }
int main ( int argc, char ** argv) { logtail::Logger::Instance().InitGlobalLoggers(); std :: cout << "BM_Regex_Match" << std :: endl ; BM_Regex_Match( 10000 ); return 0 ; }

 

这时候我们就需要注意了,我们使用行首正则时,其实往往只需要匹配单行日志开头的一部分,例如这个日志就是cnt,我们并不需要整个 .* 部分,因为匹配这部分会消耗不必要的性能。特别是当日志非常长时,这种影响尤为明显。







请到「今天看啥」查看全文