브로드캐스트 조인 vs 일반 조인 비교
일반 조인과 브로드캐스트 조인, 두 가지 방식으로 조인을 만들었어요. 이제 매니저가 Spark 최적화를 사용했을 때 성능이 얼마나 개선되는지 알고 싶어 해요. 결과가 유망하면, 필요에 따라 Spark 설정을 더 조정해 볼 기회를 드릴 예정이에요.
DataFrame normal_df와 broadcast_df가 준비되어 있어요.
이 연습은 강의의 일부입니다
PySpark로 데이터 정제하기
연습 안내
- 일반 DataFrame에서
.count()를 실행하세요. - 브로드캐스트된 DataFrame에서
.count()를 실행하세요. - 두 DataFrame의 개수와 실행 시간을 출력하고, 차이점을 기록하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
start_time = time.time()
# Count the number of rows in the normal DataFrame
normal_count = ____
normal_duration = time.time() - start_time
start_time = time.time()
# Count the number of rows in the broadcast DataFrame
broadcast_count = ____
broadcast_duration = time.time() - start_time
# Print the counts and the duration of the tests
print("Normal count:\t\t%d\tduration: %f" % (normal_count, normal_duration))
print("Broadcast count:\t%d\tduration: %f" % (broadcast_count, broadcast_duration))