영상 병합 작업 SSE로 처리하기

머지몬 3단 진화
영상 병합 작업 SSE 적용기
AUSG 7th 김수경
발표 끝났습니다.
발표 끝났습니다.
요 기능이 세상밖으로 나오기까지 7일 걸렸습니다.
이 간단한 걸 대체 왜...?
라는 의문이 드시겠죠?
저도 그랬습니다.
시작하기 전까지는요...
저의 노고가 아까워서
이 간단한 기능이 왜 그토록 오래걸렸는지의
삽질 + SSE 구현기를 발표하겠습니다.
WHY?
등장 배경
지나치게 오래걸린다..!
원본 영상의 용량 자체가 크고
영상 클립의 개수가 늘어날 수 있다는 점
등장 배경
Progress Bar 를 통해
영상의 다운로드 상황을 보여주자!
그래서 등장하게 된.. "(Video) Merge Mon"
Merge Mon Lv.1
스킬 : 영상 합치기 시, 무한 대기
서버의 상태를 어떻게 받아올 것 인가
서버는 연결 유지 X
최소한의 자원만 유지
한번 응답을 내려주면 끝이라는 것
서버의 상태를 어떻게 받아올 것 인가
• Polling
• Long Polling
• WebSocket
• SSE
Polling
• 클라이언트가 주기적으로 서버에게
요청을 보내는 방식
• 계속 요청 -> 리소스 낭비
• 일정 주기가 있다면 OK
• 단순하게 구현 가능 (e.g. SetInterval)
Long Polling
• 서버에서 변경이 있을 때까지 대기
• 지속적으로 연결 유지
• 실시간 반응이 빈번하지 않을 때 용이
WebSocket
• 전이중통신방식으로
애플리케이션 계층에서 이뤄지며...
HTTP 헤더를 첫 연결시에만 보내어 불필요한 연결과
정의 반복을 제거할 수 있다.
브로드 캐스트를 지원하고...
• 양방향통신
• 대표적인 예시 : 채팅 구현 방식
SSE
Server Sent Event
WebSocket 🆚 SSE
• 클라이언트에서 최초 요청 이후, 더이상 보낼 일 없음
(서버 단방향)
• 웹소켓보다 가벼움
• 자동 재접속 지원
기존 병합 작업
Post로 VideoInfo를 보내고 병합이 완료된 영상의 주소를 받아옴
"Pending A"의 과정이 "Pending B"의 과정에 종속
Mission 1. SSE Post로 구현하기
이것만 보고 멈췄어야했다...
Mission 1. SSE Post로 구현하기
Mission 2. 이중 SSE
중간에 영상을 합치는 작업을 진행할 정보를 담고 있는 매개체가 필요하다.
중간 매개체(DB) 선정
• 데이터 저장소로 가장 입/출력이 빠르게 이루어지는 스토리지
• 계속 데이터를 보관하지 않기 위한 TTL 설정
• ML 모델 연동과 확장성 고려
Mission 2. 이중 SSE
• Step 1 (POST)
합칠 영상 정보를 DB(Redis)에
저장하고 DB로 부터 저장된 Key값을
받아온다.
• Step 2 (GET)
받아온 Key 값을 통해 영상 병합
작업을 시도하고 이벤트 스트림을
통해 진행도를 받는다.
Mission 2. 이중 SSE
Mission 2. 이중 SSE
.....오잉
"머지몬 lv.1" 의 상태가...!
Merge Mon Lv.2
스킬 : SSE 진행도 3단계로 보내기
2단계 정체 현상
실질적으로 영상의 개수가 많아지면 과정이 더 오래걸린다..
머지몬 3단 진화의 마지막 미션
: 세부 단계를 구현하라.
그렇게 마주하게된 자그마한 또다른 미션...!
오래걸리는 구간 파악
Mission 1. 코루틴 작업 떼어내기
코루틴 작업 하나가 끝났을 때 이벤트 전송
코루틴 작업 분리
• 영상 각각의 스트림을 가져온다.
• 해당 부분에서 영상의 개수가 많아지면 오래걸리는 문제가 발생
• coroutine내부에서 각 개별 작업이 끝난 시점을 알아야한다.
코루틴 작업 분리
• Return Iterator
• 주어진 Future들에서 먼저 끝나는 것부터 차례로 순회
as_completed
코루틴 작업 분리
• FIRST 구간 전체 진행도 : 33%
• 영상 개수(총 2개)에 따른 세부 진행도
• 영상 1개 스트림 : 16%
• 영상 2개 스트림 : 33%
Video Sever SSE Response
Mission 1 Complete✨
Mission 2. MoviePy의 ProgressBar 꺼내기
를 내장하고 있는 파이썬 기반 영상 편집 라이브러리
Custom Logger
진행도 출력은 어디서 이루어지는가..
proglog logger를
커스텀하자..!
Proglog
가뭄의 단비같은..
친절한 주석 ✨
But
Proglog - callback
• 콜백 함수에 SSE EventStream의 이벤트를 넣어서 이벤트 전송
EventStream 객체 자체 넘길 수 없음
EventStream의 라이프 사이클은
SSE 객체가 생성된
첫 엔트리 포인트에서만 제어 가능.
내부의 진행상황을 밖으로 빼내기
커스텀 로거 완결판
세부 진행도 받아오기
• SECOND 구간 전체 진행도
: 33 - 66%
• Video Write 작업 진행에 따른
100% 환산 작업 수행
Video Sever SSE Response
Mission Complete✨
.....오잉
"머지몬 lv.2" 의 상태가...!
Merge Mon Lv.3
스킬 : SSE 진행도 백분율로 보내기
TLDR
1. SSE는 표준대로 GET으로 구현하자
2. SSE의 제어권 자체는 엔트리포인트 이외에는 넘길 수 없다.
3. (파이썬 한정) 만능 tqdm 라이브러리를 사용하면
진행도를 자세하게 받아올 수 있다.
SSE 구현을 위한 소소한 팁(?)
1 of 40

Recommended

AI기반 공문서 내 민감 콘텐츠 마스킹 시스템 구현_발표 자료 by
AI기반 공문서 내 민감 콘텐츠 마스킹 시스템 구현_발표 자료AI기반 공문서 내 민감 콘텐츠 마스킹 시스템 구현_발표 자료
AI기반 공문서 내 민감 콘텐츠 마스킹 시스템 구현_발표 자료sugyeong kim
28 views24 slides
posepicker_최종소개자료 by
posepicker_최종소개자료posepicker_최종소개자료
posepicker_최종소개자료sugyeong kim
51 views22 slides
[0922_ICT 멘토링] 우리 팀이 GitLab으로 협업하는 방식.pdf by
[0922_ICT 멘토링] 우리 팀이 GitLab으로 협업하는 방식.pdf[0922_ICT 멘토링] 우리 팀이 GitLab으로 협업하는 방식.pdf
[0922_ICT 멘토링] 우리 팀이 GitLab으로 협업하는 방식.pdfsugyeong kim
49 views25 slides
ChatGPT and the Future of Work - Clark Boyd by
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
28.7K views69 slides
Getting into the tech field. what next by
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
6.7K views22 slides
Google's Just Not That Into You: Understanding Core Updates & Search Intent by
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
7K views99 slides

More Related Content

Featured

Time Management & Productivity - Best Practices by
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
169.8K views42 slides
The six step guide to practical project management by
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
36.7K views27 slides
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
12.8K views21 slides
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
55.5K views138 slides
12 Ways to Increase Your Influence at Work by
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
401.7K views64 slides
ChatGPT webinar slides by
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slidesAlireza Esmikhani
30.5K views36 slides

Featured(20)

Time Management & Productivity - Best Practices by Vit Horky
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
Vit Horky169.8K views
The six step guide to practical project management by MindGenius
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
MindGenius36.7K views
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright... by RachelPearson36
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
RachelPearson3612.8K views
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present... by Applitools
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Applitools55.5K views
12 Ways to Increase Your Influence at Work by GetSmarter
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
GetSmarter401.7K views
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G... by DevGAMM Conference
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
DevGAMM Conference3.6K views
Barbie - Brand Strategy Presentation by Erica Santiago
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
Erica Santiago25.1K views
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well by Saba Software
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them wellGood Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Good Stuff Happens in 1:1 Meetings: Why you need them and how to do them well
Saba Software25.3K views
Introduction to C Programming Language by Simplilearn
Introduction to C Programming LanguageIntroduction to C Programming Language
Introduction to C Programming Language
Simplilearn8.5K views
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr... by Palo Alto Software
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
The Pixar Way: 37 Quotes on Developing and Maintaining a Creative Company (fr...
Palo Alto Software88.4K views
9 Tips for a Work-free Vacation by Weekdone.com
9 Tips for a Work-free Vacation9 Tips for a Work-free Vacation
9 Tips for a Work-free Vacation
Weekdone.com7.2K views
How to Map Your Future by SlideShop.com
How to Map Your FutureHow to Map Your Future
How to Map Your Future
SlideShop.com275.1K views
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -... by AccuraCast
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
Beyond Pride: Making Digital Marketing & SEO Authentically LGBTQ+ Inclusive -...
AccuraCast3.4K views
Exploring ChatGPT for Effective Teaching and Learning.pptx by Stan Skrabut, Ed.D.
Exploring ChatGPT for Effective Teaching and Learning.pptxExploring ChatGPT for Effective Teaching and Learning.pptx
Exploring ChatGPT for Effective Teaching and Learning.pptx
Stan Skrabut, Ed.D.57.7K views
How to train your robot (with Deep Reinforcement Learning) by Lucas García, PhD
How to train your robot (with Deep Reinforcement Learning)How to train your robot (with Deep Reinforcement Learning)
How to train your robot (with Deep Reinforcement Learning)
Lucas García, PhD42.5K views
4 Strategies to Renew Your Career Passion by Daniel Goleman
4 Strategies to Renew Your Career Passion4 Strategies to Renew Your Career Passion
4 Strategies to Renew Your Career Passion
Daniel Goleman122K views

영상 병합 작업 SSE로 처리하기