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

フェアリーデバイセズがRustを 採用して3年が過ぎました

フェアリーデバイセズがRustを 採用して3年が過ぎました

Rust.Tokyo 2022 スポンサーセッション

Satoshi Yoshikawa

September 25, 2022
Tweet

Other Decks in Programming

Transcript

  1. About me
 • Twitter/GitHub: @emergent
 • Since 2018.9
 ◦ Manager

    of Product Development Dept.
 • Publication
 ◦ 『実践Rustプログラミング入門』共著
 ◦ WEB+DB PRESS No.129 (interview)
 ◦ WEB+DB PRESS No.131 (plan)
 ◦ 技術書典『機械学習の炊いたん』
 2 Satoshi Yoshikawa / 吉川哲史
  2. 3

  3. 4

  4. Products @2018-2019
 Audio libraries written in C++ WebSocket server in

    C++ and the others in Python and TypeScript 7 Tumbler
  5. Difficulties with services handling audio
 • Theoretical and implementation difficulties

    of audio signal processing, speech recognition, etc.
 • Difficulties in APIs as a pathway for audio data
 8
  6. Difficulties with services handling audio
 • Theoretical and implementation difficulties

    of audio signal processing, speech recognition, etc.
 • Difficulties in APIs as a pathway for audio data
 9 Asynchronous communication of audio stream

  7. Products @2018-2019
 Audio libraries written in C++ WebSocket server in

    C++ and the others in Python and TypeScript 12 Tumbler
  8. Hard to maintain with C++...
 13 Write once in C++,

    run forever. PIEN CEO / CTO
 Masato Fujino
 ※He didn’t say so, (actually). 

  9. Is there the alternative of C++?
 • Want to increase

    software quality
 ◦ No more segmentation fault
 • but not at the expense of performance
 
 14
  10. Road to use Rust to our products
 1. Write codes

    in Rust
 2. Write codes in Rust
 3. Write codes in Rust
 4. Say “Rust is good!” to collegues
 5. Say “Rust is good!” to CEO
 6. Say “Rust is good!” to CEO
 7. Say “Rust is good!” to CEO
 8. Write codes in Rust
 9. Write codes in Rust
 10. Write codes in Rust
 16
  11. Steps with Rust
 17 Small start
 (microservice)
 Replacement
 New product


    Challenges
 
 ・HTTP server
 ・Connecting Redis
 Challenges
 
 ・WebSocket server 
 ・Connection control 
 Challenges
 
 ・HTTP server
 ・WebSocket API
 ・RDBMS
 ・Lambda function
 ・Layered architecture 

  12. Products with Rust
 2019 2020 2021 2022 CATS Backend microservice

    (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 18 …and many trivial works in Rust
 Publish(plan)
  13. Products with Rust
 2019 2020 2021 2022 CATS Backend microservice

    (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 19 …and many trivial works in Rust
 Publish(plan)
  14. CATS
 Purpose : to throttle simultaneous connections of APIs
 •

    Concurrent Access Throttling System
 • A simple HTTP server with Redis backend
 20 Application using Actix web Cloud Memorystore (on GCP) HTTP request HTTP response ≒ Redis

  15. Architecture
 21 CATS API server 1 API server 2 API

    server 3 Engine 1 Engine 2 Engine i … … Frontend Backend (speech recognition) CATS
  16. Good points
 • Operates stably than we thought
 • High

    performance and high load capacity
 
 • …And is contributing our business!
 23 CATS
  17. Side stories
 • Actix Web: soon to be version 1.0

    or not?
 • Participated in Rust communities and gatherings.
 ◦ “Is anyone familiar with Future anywhere?”
 25 CATS
  18. Products with Rust
 2019 2020 2021 2022 CATS Backend microservice

    (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 26 …and many trivial works in Rust
 Publish(plan)
  19. Nyaprus - Speech Recognition API
 Purpose: add functionality to speech

    recognition API
 • A frontend server of speech recognition engine
 • Has WebSocket API
 • Using warp 27 I want to use tokio-tungstenite
  20. • Replaced from C++ and Java
 • Implemented
 ◦ a

    WebSocket server
 ◦ a proxy server having connection pool
 Implementation
 28 Nyaprus Before
 After
 WS server in C++ SR frontend in Java (proprietary) SR engine (proprietary) WS server in Rust Proxy server in Rust SR engine (proprietary) WS: WebSocket 
 SR: Speech Recognition 

  21. Techniques on Rust
 • trait Stream / Sink ( on

    WebSocket server )
 • Connection Pooling ( on proxy server )
 29
  22. Connection pooling
 Problem
 Recognition speed decreases when disconnected
 due to

    cache discard in the speech recognition engine
 Solution
 Keep and reuse connections in connection pools
 33 Nyaprus
  23. Good points
 • First replacement 🎉
 • To improve development

    productivity
 ◦ Used task runner (cargo-make)
 ◦ Used container (Docker, CI/CD)
 ◦ Created testing tool (in Rust)
 37 Nyaprus
  24. Side stories
 • Cache problems were discovered just before release


    ◦ Prototype implemented in 1 day
 ◦ After 2 weeks of testing & brushing up
 ◦ Managed to release it! 🎉
 38 Nyaprus
  25. Products with Rust
 2019 2020 2021 2022 CATS Backend microservice

    (small start) Nyaprus Speech Recognition API (replacement) LINKLET (new product) Product development
 Personal activity
 WEB+DB PRESS No.131 Publish Interviewed 39 …and many trivial works in Rust
 Publish(plan)
  26. 42

  27. Challenges
 • “Web service” development (for me)
 • Developed by

    team with multiple people
 • Continuous development and release
 43 LINKLET
  28. Architecture (part)
 44 api-server Web Frontend notification zoom auth0 tlpf-connector

    mqtt-connector db-connector Auth0 Zoom Device Controller RDBMS httpclient WebSocket notificaiton HTTP(S) Webhook (HTTP(S)) cipher LINKLET
  29. Challenges
 • Asynchronous communication with LINKLET devices
 ◦ Taking care

    of the state of devices
 ▪ Power ON / OFF
 ▪ Online / Offline
 ◦ Non-blocking API
 ▪ HTTP and WebSocket (push)
 46 LINKLET
  30. Challenges (with Rust)
 • Wrestling with Diesel (and SQL)
 •

    Layered architecture (in progress)
 ◦ Using mock (mockall crate)
 • AWS Lambda function in Rust
 47 LINKLET
  31. Advantages in Rust
 • Refactoring with peace of mind😌
 ◦

    by
 ▪ Compilation errors are well attended
 ▪ Interfaces are well typed
 48 LINKLET
  32. Steps with Rust
 49 Small start
 (microservice)
 Replacement
 New product


    Challenges
 
 ・HTTP server
 ・Connecting Redis
 Challenges
 
 ・WebSocket server 
 ・Connection control 
 Challenges
 
 ・HTTP server
 ・WebSocket API
 ・RDBMS
 ・Lambda function
 ・Layered architecture 

  33. Conclusions
 • Rust is powerful to create web applications
 ◦

    But still less than 30% of our total products
 50
  34. Futures
 • Grow our products more with Rust (and modern

    techs)
 ◦ more reliable
 ◦ more speedy
 ◦ higher performance
 51
  35. We are hiring!
 • Frontend / Backend developer
 • Device

    Engineer
 • Product Manager
 • …and more
 52
  36. We are hiring!
 • Frontend / Backend developer
 • Device

    Engineer
 • Product Manager
 • …and more
 53 Please check the job board out!