Diese Präsentation wurde erfolgreich gemeldet.
Wir verwenden Ihre LinkedIn Profilangaben und Informationen zu Ihren Aktivitäten, um Anzeigen zu personalisieren und Ihnen relevantere Inhalte anzuzeigen. Sie können Ihre Anzeigeneinstellungen jederzeit ändern.

ドワンゴでのScala活用事例「ニコニコandroid」

10.915 Aufrufe

Veröffentlicht am

  • Als Erste(r) kommentieren

ドワンゴでのScala活用事例「ニコニコandroid」

  1. 1. Use of Scala in dwangoniconico Android API 後藤 哲志 (Satoshi Goto) DWANGO Co.,Ltd.
  2. 2. AttentionWe talk about API serverusing Scala and Playniconico Android (app) iswritten by Java
  3. 3. ContentsSelf-introduction (自己紹介)Project introduction (プロジェクト紹介)Scala pros/cons (いいところ 悪いところ)
  4. 4. Satoshi Gotoニコニコ事業統括本部 プラットフォーム事業本部 第一企画開発部 第4セクションニコニコAndroid サーバチーム所属id:mtgto (twitter, GitHub, Qiita)
  5. 5. Works atniconico
  6. 6. niconico is 6-year-old PC (Windows, Mac, Linux, etc.) Feature phone (docomo, au, softbank, willcom) iPhone PS Vita TV WiiU Windows 8
  7. 7. niconico is 6-year-old PC (Windows, Mac, Linux, etc.) Feature phone (docomo, au, softbank, willcom) iPhone PS Vita TV WiiU &Android! Windows 8
  8. 8. Project History2012/2 Project launched2012/8 au STB App released2012/11 Android App releasedDeployed 22 times2.5 million requests / day
  9. 9. Our teamPlanner: 1Android developers: 5API server developers: 6Infra-engineers: 2
  10. 10. API server members@tomoyoshi_ogura@kozo1215@fedista@mitikage@kimwoonsung@mtgto
  11. 11. API server membersOld member@tomoyoshi_ogura@kozo1215@fedista I♥ Scala@mitikage@kimwoonsung@mtgto
  12. 12. Internal APIVideo API niconico Android APILive Scala 2.9.1API Play 2.0
  13. 13. niconico Android API isdwango s first servicewritten in Scala
  14. 14. 74 APIVideo (動画) Ranking, Search, Tags, MyListLive (生放送) Ranking, Search, TagsChannel, Community, News
  15. 15. Niconico Android is PROXY ?
  16. 16. Niconico Android is ! N O PROXY ?
  17. 17. Re-defined typed model Anticorruption LAYER (腐敗防止層) lingo ambiguous(社内用語) various definition characteristics (曖昧な定義) nullable
  18. 18. Why Scala ?Increasing interests in Scala Scala workshop in dwangoStrong compiler checkExperimental project
  19. 19. Our productsCore libraryAPI serverManagement server
  20. 20. Corebased on DDD conceptScala (& Java enumeration)sbt + IntelliJ IDEA (sbt-idea)jedis (redis client) for caching Using Java serializationSpecs 2 + Mockito
  21. 21. Open APIbased on Core LibraryPlay 2.0.2 (JSON only)Redis-based sessions (using jedis)CSRF-free customized Action (Play)Daemonized (Apache Daemon)
  22. 22. Managementbased on Core LibraryPlay 2.0.2 (Internal web system)Statistics and OperationsDaemonized (Apache Daemon)
  23. 23. Project scale # of files # of tests LOC CORE 665 976 52kOPEN API 75 530 21kmanage 32 173 2k
  24. 24. TEST (Core) Almost 1000TODO: Jenkinsのスクリーンショット TODO:テスト件数 80% Coverage
  25. 25. ProsOptionmatch & sealed trait
  26. 26. Option∼Say goodbye to NullPointerException∼
  27. 27. Null check is boring Java Scala
  28. 28. match &sealed trait
  29. 29. match
  30. 30. match
  31. 31. match Use scalac option -Xfatal-warnings
  32. 32. Conscase class limitationJenkins server swap outPlay framework CSRF / Akka
  33. 33. Case Class
  34. 34. Case class useful! equals hashCode toString etc. defined automatically!
  35. 35. Tuple22limitation!
  36. 36. Case classesrepresent XML API
  37. 37. Case classesrepresent XML API 32 Elements
  38. 38. Case classesrepresent XML API
  39. 39. Case classesrepresent XML API 96 Elements
  40. 40. JenkinsSwap out
  41. 41. Jenkins swap outScalac obtains over 1GB memory
  42. 42. Jenkins swap outScalac obtains over 1GB memory Restricted the number of simultaneous jenkins jobs... (4 -> 2 -> 1)
  43. 43. Play / CSRF
  44. 44. CSRF self check Implements Customized Action to check CSRF like below:• if Method == POST ¦ PUT ¦ DELETE • if request.body( token ) != token • BadRequest
  45. 45. Play / Akka
  46. 46. Request Overflowed In production environment, Play causes many exceptions
  47. 47. Request Overflowed In production ERROR play Cannot invoke the action, eventually got an error: environment, PlayThrown(akka.pattern.AskTimeoutExc causes many out) eption: Timed exceptions
  48. 48. Few documentation for Akka...http://www.playframework.com/documentation/2.0.4/ AkkaCore
  49. 49. Increase number of threads from 24 to 100Extends timeouts from 5 to 10 secondsAlmost errors aren’t occurred
  50. 50. ConclusionWe rarely facedcritical troubleswhile we are usingScala in our project
  51. 51. Thank you for listening!https://play.google.com/ store/apps/details? id=jp.nicovideo.android

×