How would you optimize a Python script that processes large-scale streaming logistics data?
Implement top_k_hubs(events, k) to consume event records, aggregate delay values by hub, and return up to k hubs ordered by total delay descending, then hub name ascending. Each event is a map with string hub and integer delay; return an array of [hub, total_delay] pairs.
Example: events = [{"hub":"LAX","delay":2},{"hub":"LAX","delay":4},{"hub":"LHR","delay":6}], k = 2 returns [["LAX",6],["LHR",6]].
def top_k_hubs(events, k):