Google VO 面试真题解析:RPC 超时检测与日志统计

31次阅读
没有评论

Imagine you have an RPC server that produces a log of entries, and you’re analyzing it offline. There are two entries for each call: one when the RPC starts and one when the RPC finishes processing. We’d like to know as soon as possible if there’s an RPC that took too much time / timed out.

With timeout 3

Schema: <RpcId, Timestamp, Start or End>

Example log:

ID 1, 0, Start
ID 2, 1, Start
ID 1, 2, End
ID 3, 6, Start
ID 2, 7, End
ID 3, 8, End

Find the top ten most frequent IP addresses from a web server log file.

A sample line from the log file:

14716104719, GET, /index.html, 132.49.16.172, ...

Part 2

Several IP addresses can have the same count. Let’s write code to output the top 10 counts with the list of IP addresses for each count, rather than the top 10 IPs.

You can optionally reuse all or parts of existing code in 1.

这道题核心是在离线日志中做两类统计:第一部分是对 RPC 的 Start/End 事件按 RpcId 配对,计算每个调用的持续时间,并尽早发现是否有请求超过给定 timeout;第二部分是对 Web Server 日志中的 IP 做频次统计,先汇总每个 IP 的出现次数,再按次数从高到低输出前 10 个频次区间,并把同频次的 IP 一起列出。通常会用哈希表保存计数或开始时间,用一次扫描完成记录,再结合排序、堆或分组结构输出结果。

正文完
 0