我正在开发一个慢速查询日志解析器包,该包与golang中的慢速查询日志重放器相关联。对于重修器,请提供以下代码段(为了便于阅读,我在其中添加了注释):
for {
// method from my package that returns a Query object, containing headers values
// and the query itself
q := p.GetNext()
if q == (query.Query{}) {
break
}
db.logger.Tracef("query: %s", q.Query)
// we send the SQL query to a chan that is read by workers.
// workers just execute the query on the database, that's all.
// results from the db query are handled in another piece of the code, it doesn't really
// matter here
queries <- q.Query
// We need a reference time
if firstPass {
firstPass = false
previousDate = q.Time
continue
}
// Time field contains the Time: field value in the query header
now := q.Time
sleeping := now.Sub(previousDate)
db.logger.Tracef("next sleeping time: %s", sleeping)
time.Sleep(sleeping) // Here is my issue. For MariaDB the value is < 0 so no sleep is done
// For MariaDB, when there is multiple queries in a short amount of
// time, the Time field is not repeated, so we do not have to update
// the previous date.
if now != (time.Time{}) {
previousDate = now
}
}
我遇到了一个有趣的问题:在MariaDB慢速查询日志中,如果2个(或更多)查询彼此接近,则标头中没有Time:字段,这减少了上一个代码片段中的数量。但是,对于MySQL风格的慢速查询日志,查询标头中始终存在Time:字段,这意味着每个查询的睡眠都已完成(即使对于μs睡眠持续时间)。time.Sleep(sleeping)
我注意到MariaDB和MySQL日志之间存在巨大的重播时间差;MariaDB重放持续时间与实时时间非常相似(日志文件的第一个和最后一个查询之间的时间差),但另一方面,MySQL重放时间比IRL高得多。玩后,我注意到问题来自,特别是从中耗费了CPU时间。pproftime.Sleepruntime.Futex
我做了一些基准测试,持续时间结果与完成的数量相关(MySQL比MariaDB高)。time.Sleep
因此,我不是在单个线程中完成所有操作,而是寻找一种不同的方法来并行执行它们而不改变有效时间,但我无法找到一种方法来做到这一点。time.Sleep
www说
守候你守候我
随时随地看视频慕课网APP
相关分类