Quay lại bộ đề
Question #249 Topic 1
You are analyzing the price of a company's stock. Every 5 seconds, you need to compute a moving average of the past 30 seconds' worth of data. You are reading data from Pub/Sub and using DataFlow to conduct the analysis. How should you set up your windowed pipeline?
Bạn đang phân tích giá cổ phiếu của một công ty. Cứ sau 5 giây, bạn cần tính trung bình động của dữ liệu trong 30 giây qua. Bạn đang đọc dữ liệu từ Pub/Sub và sử dụng Dataflow để tiến hành phân tích. Bạn nên thiết lập đường ống dữ liệu phân vùng theo cửa sổ (windowed pipeline) như thế nào?
A
Use a fixed window with a duration of 5 seconds. Emit results by setting the following trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
Sử dụng cửa sổ cố định (fixed window) với thời lượng 5 giây. Phát ra kết quả bằng cách thiết lập trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
B
Use a fixed window with a duration of 30 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow().plusDelayOf (Duration.standardSeconds(5))
Sử dụng cửa sổ cố định (fixed window) với thời lượng 30 giây. Phát ra kết quả bằng cách thiết lập trigger: AfterWatermark.pastEndOfWindow().plusDelayOf (Duration.standardSeconds(5))
C
Use a sliding window with a duration of 5 seconds. Emit results by setting the following trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
Sử dụng cửa sổ trượt (sliding window) với thời lượng 5 giây. Phát ra kết quả bằng cách thiết lập trigger: AfterProcessingTime.pastFirstElementInPane().plusDelayOf (Duration.standardSeconds(30))
D
Use a sliding window with a duration of 30 seconds and a period of 5 seconds. Emit results by setting the following trigger: AfterWatermark.pastEndOfWindow ()
Sử dụng cửa sổ trượt (sliding window) với thời lượng 30 giây và chu kỳ (period) 5 giây. Phát ra kết quả bằng cách thiết lập trigger: AfterWatermark.pastEndOfWindow()
Giải thích & Tài liệu tham khảo
Yêu cầu tính toán một giá trị trung bình động trên dữ liệu của 30 giây qua (độ rộng cửa sổ - window duration = 30 seconds) và được cập nhật định kỳ mỗi 5 giây (chu kỳ trượt - window period/slide = 5 seconds) trong Apache Beam / Dataflow:
- Sử dụng Cửa sổ trượt (Sliding Window) có độ rộng 30 giây và chu kỳ 5 giây (Lựa chọn D): Đây là mô hình cửa sổ chuẩn để tính toán trung bình động (moving average). Các cửa sổ sẽ chồng chéo lên nhau. Bằng cách thiết lập kích hoạt khi watermark vượt qua cuối cửa sổ (
AfterWatermark.pastEndOfWindow()), hệ thống sẽ đảm bảo tính toán đầy đủ dữ liệu khi tất cả dữ liệu trong cửa sổ trượt đã đến. - Lựa chọn A & B: Cửa sổ cố định (Fixed Window) không chồng chéo nhau, do đó không thể tính trung bình động của 30 giây qua cứ mỗi 5 giây.
- Lựa chọn C: Cửa sổ trượt có thời lượng 5 giây không chứa đủ dữ liệu của 30 giây để tính trung bình động.
(Đáp án được gợi ý bởi AI)