Upgrade to Pro — share decks privately, control downloads, hide ads and more …

카카오워크 메시징 엔진의 Rust 교체 개발 사례 from C

kakao
November 01, 2024

카카오워크 메시징 엔진의 Rust 교체 개발 사례 from C

#RUST #메신저

기존에 C++로 개발된 카카오워크의 대량 트래픽 메시징 엔진을 Rust 기반으로 리팩토링 및 고도화한 사례를 발표합니다. Rust의 장점을 활용하여 메모리 안전성을 확보하고 성능을 개선했던 방법을 공유하며, 기 제공중인 서비스와의 안정적인 교체 사례도 함께 제공합니다.

발표자 : robby.s
KakaoWork 메시징 서버 개발하고 있는 Robby 입니다.

kakao

November 01, 2024
Tweet

More Decks by kakao

Other Decks in Programming

Transcript

  1. ↟ $ ↟ *0FWFOUNVMUJQMFYJOHFQPMMࢎਊ೧ࢲUISFBE - QPPMӝ߈SFBDUPS૒੽ҳഅ ↟ 3FBDUPSࢿמ੗୓חաࢁ૑ঋ਺ CPPTUBTJP৬௾ର੉হ਺ ↟

    ؀ࠗ࠙੄OFUXPSLJPBQJܳCMPDLJOHਵ۽ࢎਊ  XFCTPDLFUTFOESFDFJWF  HSQDSFRVFTU - SFTQPOTF ↟ CMPDLJOHBQJ਽׹ਸӝ׮ܻחزউUISFBETVTQFOE ↟ HSQDಣӐSFTQPOTFEFMBZNT җࠗೞदNT ↟ UISFBETVTQFOE۽ੋೠࢿמ੷ೞܳழߡೞӝਤ೧ࢲUISFBEQPPMਸ୭؀ѐө૑ࢎਊ ↟ ࢲߡҗࠗೞदBDUJWFUISFBEDPVOUө૑࢚थೞҊ DQVGVMM ↟ TUSFTTUFTUदр೵੸DSBTI ӝઓ'MJHIU
  2.  /FUXPSL*0ࢿמ  ؀ਊ۝ݫݽܻ੄ബਯ੸ੋҙܻ  .VMUJ - UISFBEউ੿ࢿ  ѐߊ

    ਬ૑ࠁࣻಞ੄ࢿ ରࣁ؀ fl JHIUҳഅ঱যࢶఖ 3VTU
  3.  /BUJWFDPNQJMF঱য  $$ زੌೠࣻળ੄ࢿמ  /P($  ਬ૑ࠁࣻউ੿ࢿಞ੄ࢿ 

    TUSPOHUZQFE  .FNPSZ4BGFUZ ↟ 0XOFSTIJQ ↟ #PSSPXJOH ↟ .VUBCJMJUZ 3VTU 1SPHSBNNJOH-BOHVBHFBOEDPNQJMFS#FODINBSLT ↟  IUUQT QSPHSBNNJOH - MBOHVBHF - CFODINBSLTWFSDFMBQQSVTU
  4. 0XOFSTIJQ struct Student { id: i64, name: String, score: i32,

    } fn main() { let student_1 = Student { id: 1, name: String::from(“Robby”), score: 100, }; let student_2 = student_1; println!(“student_1={}”, student_1.name); println!(“student_2={}”, student_2.name); } CPSSPXPGNPWFEWBMVFATUVEFOU@AWBMVFCPSSPXFEIFSFBGUFSNPWF ______________ let student_2 = student_1; 3VMFPXFS߸ࣻחѐ݅ઓ੤ೠ׮
  5. 0XOFSTIJQ struct Student { id: i64, name: String, score: i32,

    } fn main() { let student = Student { id: 1, name: String::from(“Robby”), score: 100, }; print_score(student); print_score(student); } fn print_score(student: Student) { println!(“name={} score={}”, student.name, student.score); } VTFPGNPWFEWBMVFATUVEFOUAWBMVFVTFEIFSFBGUFSNPWF _______ WBMVFNPWFE
  6. 0XOFSTIJQ#PSSPXJOH struct Student { id: i64, name: String, score: i32,

    } fn main() { let student = Student { id: 1, name: String::from(“Robby”), score: 100, }; print_score(&student); print_score(&student); } fn print_score(student: &Student) { println!(“name={} score={}”, student.name, student.score); }
  7. 0XOFSTIJQ#PSSPXJOH fn main() { let student = Student { id:

    1, name: String::from(“Robby”), score: 100, }; let student_ref_1 = &student; let student_ref_2 = &student; print_score(student_ref_1); print_score(&student); print_score(student_ref_2); } fn print_score(student: &Student) { println!(“name={} score={}”, student.name, student.score); }
  8. #PSSPXJOH.VUBCJMJUZ fn main() { let student = Student { id:

    1, name: String::from(“Robby”), score: 100, }; update_score(&student, 90); } fn update_score(student: &Student, score: i32) { student.score = score; } DBOOPUBTTJHOUPATUVEFOUTDPSFA XIJDIJTCFIJOEBAASFGFSFODF TPUIFEBUBJUSFGFSTUPDBOOPUCFXSJUUFO ______________
  9. #PSSPXJOH.VUBCJMJUZ fn main() { let student = Student { id:

    1, name: String::from(“Robby”), score: 100, }; update_score(&student, 90); } fn update_score(student: &mut Student, score: i32) { student.score = score; } FYQFDUFENVU4UVEFOU GPVOE4UVEFOU _________
  10. #PSSPXJOH.VUBCJMJUZ fn main() { let student = Student { id:

    1, name: String::from(“Robby”), score: 100, }; update_score(&mut student, 90); } fn update_score(student: &mut Student, score: i32) { student.score = score; } DBOOPUNVUBUFJNNVUBCMFWBSJBCMFATUVEFOUA _____________
  11. #PSSPXJOH.VUBCJMJUZ fn main() { let mut student = Student {

    id: 1, name: String::from(“Robby”), score: 100, }; update_score(&mut student, 90); } fn update_score(student: &mut Student, score: i32) { student.score = score; }
  12. #PSSPXJOH.VUBCJMJUZ fn main() { let student = Student { id:

    1, name: String::from(“Robby”), score: 100, }; let mut student = student; update_score(&mut student, 90); } fn update_score(student: &mut Student, score: i32) { student.score = score; }
  13. #PSSPXJOH.VUBCJMJUZ fn main() { let mut student = Student {

    id: 1, name: String::from(“Robby”), score: 100, }; let student_ref = &student; print_score(student_ref); update_score(&mut student, 90); print_score(student_ref); } fn update_score(student: &mut Student, score: i32) { student.score = score; } fn print_score(student: &Student) { println!(“name={} score={}”, student.name, student.score); } DBOOPUCPSSPXATUVEFOUABTNVUBCMFCFDBVTFJUJTBMTPCPSSPXFEBTJNNVUBCMF NVUBCMFCPSSPXPDDVSTIFSF __________
  14. #PSSPXJOH.VUBCJMJUZ fn main() { let mut student = Student {

    id: 1, name: String::from(“Robby”), score: 100, }; let student_ref = &student; print_score(student_ref); update_score(&mut student, 90); print_score(&student); } fn update_score(student: &mut Student, score: i32) { student.score = score; } fn print_score(student: &Student) { println!(“name={} score={}”, student.name, student.score); }
  15. #PSSPXJOH4JOHMF - UISFBE fn init_students() -> HashMap<i32, Student> { let

    mut students = HashMap::new(); … students } fn print_students(students: &HashMap<i32, Student>) { … } fn update_students(students: &mut HashMap<i32, Student>) { … } fn foo() { let mut students = init_students(); print_students(&students); update_students(&mut students); print_students(&students); }
  16. #PSSPXJOH.VMUJ - UISFBE fn init_students() -> HashMap<i32, Student> { let

    mut students = HashMap::new(); … students } fn print_students(students: &HashMap<i32, Student>) { … } fn update_students(students: &mut HashMap<i32, Student>) { … } fn foo() { let mut students = init_students(); std::thread::spawn(|| { print_students(&students); }); std::thread::spawn(|| { update_students(&mut students); }); print_students(&students); } DMPTVSFNBZPVUMJWFUIFDVSSFOUGVODUJPO  CVUJUCPSSPXTATUVEFOUTA
  17. 0XOFSTIJQ.VMUJ - UISFBE fn init_students() -> HashMap<i32, Student> { let

    mut students = HashMap::new(); … students } fn print_students(students: &HashMap<i32, Student>) { … } fn update_students(students: &mut HashMap<i32, Student>) { … } fn foo() { let mut students = init_students(); std::thread::spawn(move || { print_students(&students); }); std::thread::spawn(move || { update_students(&mut students); }); print_students(&students); } VTFPGNPWFEWBMVFATUVEFOUTA CPSSPXPGNPWFEWBMVFATUVEFOUTA
  18. .VMUJ - UISFBE"SD5 fn init_students() -> HashMap<i32, Student> { let

    mut students = HashMap::new(); … students } fn print_students(students: &HashMap<i32, Student>) { … } fn update_students(students: &mut HashMap<i32, Student>) { … } fn foo() { let students = init_students(); let students = Arc::new(students); let students_1 = students.clone(); std::thread::spawn(move || { print_students(&students_1); }); let mut students_2 = students.clone(); std::thread::spawn(move || { update_students(&mut students_2); }); print_students(&students); } DBOOPUCPSSPXEBUBJOBOA"SDABTNVUBCMF
  19. .VMUJ - UISFBE"SD.VUFY5 fn init_students() -> HashMap<i32, Student> { let

    mut students = HashMap::new(); … students } fn print_students(students: &HashMap<i32, Student>) { … } fn update_students(students: &mut HashMap<i32, Student>) { … } fn foo() { let students = init_students(); let students = Mutex::new(students); let students = Arc::new(students); let students_1 = students.clone(); std::thread::spawn(move || { let read_locked_students = students_1.lock().unwrap(); print_students(&read_locked_students); }); let students_2 = students.clone(); std::thread::spawn(move || { let mut write_locked_students = students_2.lock().unwrap(); update_students(&mut write_locked_students); }); print_students(&students.lock().unwrap()); }
  20. async fn fetch_user(id: i64) -> Result<User, NetworkError> { … }

    async fn fetch_user_profile_image(id: i64) -> Result<Image, NetworkError> { let user = fetch_user(id).await?; fetch_profile_image(user.profile_image_url) } BTZODBXBJU
  21. 3VTUZ'MJHIUXPSLUJNFMJOF         

         4BOECPY2" 4USFTTUFTU ↟ ࢿמ୭੸ച ↟ ܻಖష݂ ഥ ↟ EFBEMPDL ↟ DSBTI ↟ DSBTI  ѐߊୡӝपࣻBTTFSU  ઱݅ীߣഐ୹ػBQJߡӒ ↟ BSSBZCPVOEFSSPS  ৻ࠗMJCSBSZߡӒ ࣁࠗӝמBQJҳഅ ↟ XFCTPDLFUBQJ ↟ SFTUBQJ ↟ HSQD ↟ fl JHIUDMVTUFSBQJ 3VTU fl JHIUѐߊद੘ BQQTLFMFUPO ↟ -PHJO ↟ .FTTBHF3FMBZ ↟ 3VTU೟ण $#52" QBSUJBMQSPEVDUJPO ਘੌ 1SPEVDUJPO ↟ ӝઓ$ 'MJHIU࠙ࢳ ↟ ࢿמపझ౟ ↟ 3VTU೟ण
  22. 3VTUJOQSPEVDUJPO .JDSPTPGU (PPHMF "84 $MPVE fl BSF %JTDPSE OQNKTDPN ↟

    CJMMJPOQBDLBHFEPXOMPBEQFSEBZ ↟  3VTUOQN8IJUFQBQFS 9 UXJUFS ↟  GSPN(PUP3VTU
  23. 2"