deepflowio / deepflow-app

GNU Affero General Public License v3.0
11 stars 9 forks source link

feat: fix host_clock_correction for different host #277

Closed taloric closed 1 month ago

taloric commented 1 month ago

基于收集到的主机间时间差,对每个主机(agent_id)计算出一个调整参数 调整前提:

  1. 基于一个 hostX 作为基准做统一调整,所有 host 对齐到该 hostX
  2. 理论上要以 rootSpan 的 host 作为基准,这里等价于"没有成为 child"的 host
  3. 注意可能出现多个基准 host,比如存在如下情况:[hostX, hostY], [hostY, hostZ], [hostA, hostB], [hostA, hostC], 此时应该存在 hostX/hostA 两个基准

调整逻辑:

  1. 基准 host 不做调整,仅对基准 host 以下的 host 做调整(准确地说是只对 child host 调整)
  2. 对一组 [hostA, hostB],如果存在 [hostX, hostA] 且 hostA 已被调整,则 hostB 的调整值需要加上 hostA 的调整值,以对齐到 hostX
  3. 每一组 host 的调整值都是 min(abs(max, min)),即只做“最小调整”,但要注意保持正负

Based on the time difference between hosts by collected, a tuning parameter is calculated for each host (agent_id) Before adjust we need to know:

  1. We need to based on one hostX as the benchmark and align all hosts to this hostX
  2. Technically, the host of rootSpan should be the benchmark, which is equivalent to the host that "did not become a child"
  3. Notice that multiple benchmark hosts may exist. For example, the following situation : [hostX, hostY], [hostY, hostZ], [hostA, hostB], [hostA, hostC]. In this case, hostX/hostA both are the benchmark. ​ How to do adjust:
  4. The base host adjust is not available, only the host below the base host is adjusted (in fact, only the child host is adjusted).
  5. For a group of [hostA, hostB], if [hostX, hostA] exists and hostA has been adjusted, the adjusted value of hostB needs to be added to the adjusted value of hostA to align with hostX
  6. The adjustment value of each group of host is min(abs(max, min)), it means only make the "minimum adjustment", also we need to keep positive and negative for the value
taloric commented 1 month ago

关于为什么只做”最小调整“,而不是“平均值调整”:

假设追踪是这样的: image

假设存在这样的误差:红色 node1 作为基准时间,绿色 node2 晚 10ms,橙色 node3 早 10ms 基于时间误差,我们得到了这样的图: image

按照上面的逻辑,如果只做“最小调整”,我们的调整结果是: image

但如果同样按照上面逻辑,把“最小调整”替换为“平均值调整”,调整结果则变成:橙色的 node3 发生矛盾,无论往左还是往右都无法调整对(其实就是绿色 node2 过调整了) image