SlideShare a Scribd company logo
The Trial and Error in 
Releasing GREE Chat 
Shun Ozaki, Takayuki Hasegawa 
Copyright © GREE, Inc. All Rights Reserved. 
Scala Matsuri2014 B-6 
GREE's First Scala Product
Copyright © GREE, Inc. All Rights Reserved. 
Self Introduction 
• Shun Ozaki 
• @wozaki 
• Joined in April, 2013 
• Android Application 
• Takayuki Hasegawa 
• @hase1031 
• Joined in April, 2013 
• NLP, Machine Learning 
1/56
Copyright © GREE, Inc. All Rights Reserved. 
GREE Chat 
• Released at June 2 
2/56
How to build our system for hundreds of 
thousands daily users 
Copyright © GREE, Inc. All Rights Reserved. 
Agenda 
3/56
Goal 
Share our knowledge we got through 
the development of GREE Chat 
Copyright © GREE, Inc. All Rights Reserved. 
• Why Scala? 
• Team development 
• Decision of frameworks 
• Obstacles & workarounds 
4/56
Copyright © GREE, Inc. All Rights Reserved. 
Outline 
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary 
Copyright © GREE, Inc. All Rights Reserved. 
Outline
Decide the Language 
based on the Requirement 
Copyright © GREE, Inc. All Rights Reserved.
Requirements 
• Hundreds of thousands daily users 
• Real-time response 
Copyright © GREE, Inc. All Rights Reserved. 
 Connect with streaming 
• Run on a small number of servers 
 Utilize server resource effectively 
• Maintain for over 5 years 
8/56
Copyright © GREE, Inc. All Rights Reserved. 
◎ GREE uses PHP so heavily 
• Many libraries and know-how in GREE 
△ Streaming 
• #connections = #processes 
△ Single thread, multi process 
• Overhead of spawning an OS process 
△ Maintainability 
• Dynamic typing 
9/56
◎Compatible with concurrent programming 
◎One process, many connections 
◎High maintainability 
• Static typing 
• Functional programming (no side effects) 
◎Stimulate new technology learning in GREE 
• Open to new languages & technologies! 
Copyright © GREE, Inc. All Rights Reserved. 
Scala! 
10/56
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary 
Copyright © GREE, Inc. All Rights Reserved. 
Outline
After adopting Scala … 
Copyright © GREE, Inc. All Rights Reserved.
Only two Scala programmers in a team of seven 
Copyright © GREE, Inc. All Rights Reserved. 
Shortage of Scala experts 
2/ 
7 
13/56
Only two Scala programmers in a team of seven 
We must build up our skill! 
Copyright © GREE, Inc. All Rights Reserved. 
Shortage of Scala experts 
2/ 
7 
14/56
Copyright © GREE, Inc. All Rights Reserved. 
Learning of Scala 
1. Self study 
2. Study club 
3. Pair programming 
15/56
Copyright © GREE, Inc. All Rights Reserved. 
1. Self Study 
Understand the basic syntax
Copyright © GREE, Inc. All Rights Reserved. 
1. Self Study 
Books 
17/56
Copyright © GREE, Inc. All Rights Reserved. 
1. Self Study 
Documents by Twitter 
https://twitter.github.io/scala_school/ http://twitter.github.io/effectivescala/ 18/56
Copyright © GREE, Inc. All Rights Reserved. 
1. Self Study 
Source code from OSS 
19/56
Copyright © GREE, Inc. All Rights Reserved. 
2. Study Club 
Share what we learned by ourselves 
Introduction to functional programming
2. Study Club 
• Each engineer solves the problems 
provided by Scala experts 
Copyright © GREE, Inc. All Rights Reserved. 
• e.g., Binary Tree, Fibonacci Sequence 
21/56
• Example of factorial generation algorithm 
Copyright © GREE, Inc. All Rights Reserved. 
2. Study Club 
Discussion with Members 
Use var Use recursion 
22/56
• Example of factorial generation algorithm 
Use var Use recursion 
Copyright © GREE, Inc. All Rights Reserved. 
2. Study Club 
Discussion with Members 
No side effect 
23/56
3. Pair Programming 
Practice by using the knowledge 
Copyright © GREE, Inc. All Rights Reserved. 
obtained from study club
Copyright © GREE, Inc. All Rights Reserved. 
3. Pair Programming 
• Effective learning 
• Learn about symbols (e.g., +, @), which cannot 
be searched easily on the Internet 
• Supplement the knowledge not taught at 
study club 
• Complex syntaxes (e.g., implicit, currying) 
• Development tools (e.g., sbt, IntelliJ) 
25/56
Copyright © GREE, Inc. All Rights Reserved. 
Summary: Adopting Scala 
• Reasons of selecting Scala 
• Compatible with concurrent programming 
• Maintainability because of static typing 
• Learning of Scala 
• Self Study, Study Club, Pair Programming 
• Big burdens on Scala experts 
• Needed for teaching team members 
• Maintain the quality of codes 
26/56
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary 
Copyright © GREE, Inc. All Rights Reserved. 
Outline
Architecture of Backend (simplified) 
Copyright © GREE, Inc. All Rights Reserved. 
• Servers separated by Queues 
• API Server: Process users’ requests 
• EventBus Server: Process events in Queue 
• Stream Server: Supply event to connected users 
28/56
Role of Each Server 
Copyright © GREE, Inc. All Rights Reserved. 
and Framework
Copyright © GREE, Inc. All Rights Reserved. 
API Server 
Process users’ requests 
• Enqueue events 
• e.g., Send message 
Join/leave conversation 
• Techniques to process a lot of requests 
• Delegate heavy tasks (e.g., Disk I/O) to others 
• Logic is written to run asynchronously 
• scala.concurrent.Future 
30/56
• RPC system for JVM based on Netty 
• Support us to write asynchronous logic 
Copyright © GREE, Inc. All Rights Reserved. 
• Used by large scale web services 
• e.g., Twitter, Tumblr, Foursquare, Pinterest 
• Equipped with various clients 
• Redis, Memcached 
• With retry policy, connection pools 
31/56
Copyright © GREE, Inc. All Rights Reserved. 
EventBus Server 
Process events in Queue 
• Examples of tasks 
• Logging 
• Inquire GREE internal system 
• Store events in DB 
• etc. 
• Problems of concurrent processing 
• Deadlock, race condition, … 
32/56
Framework to write concurrent, distributed 
logic more easily 
• No need to handle shared resources 
Copyright © GREE, Inc. All Rights Reserved. 
• Race condition, dead-lock 
• Logic separation 
• Parent-Child 
• Fault tolerance 
33/56
Copyright © GREE, Inc. All Rights Reserved. 
Example of Akka 
34/56
Copyright © GREE, Inc. All Rights Reserved. 
Example of Akka 
Match by Event type 
35/56
Copyright © GREE, Inc. All Rights Reserved. 
Example of Akka 
Send copy to child 
36/56
Copyright © GREE, Inc. All Rights Reserved. 
Example of Akka 
log 
37/56
Copyright © GREE, Inc. All Rights Reserved. 
Stream Server 
Supply events to connected users 
• Connect by streaming 
• Increase connections as much as possible 
• Keep users data in the memory to reduce I/O 
• Asynchronous I/O by Finagle, Akka 
• Task division by Akka 
• Supply events to users 
• Update users data 
• Send KeepAlive to users 
38/56
Copyright © GREE, Inc. All Rights Reserved. 
Summary: Architecture 
• Each server is separated by Queue 
• API, EventBus, Stream Server 
• Framework is selected by considering 
asynchronous processing 
• Finagle, Akka 
• Task is divided by Akka 
• Easy to write concurrent logic 
39/56
Copyright © GREE, Inc. All Rights Reserved. 
Outline 
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary
Copyright © GREE, Inc. All Rights Reserved. 
Obstacles 
1.JVM 
• Full GC 
2. Self-created Scala library 
• Sharding 
• ID Architecture 
41/56
Full GC 
Problems 
Copyright © GREE, Inc. All Rights Reserved.
• Scala runs on JVM 
• We want to prevent “stop the world” 
• GC in young generation is faster than full GC 
• Try not to let it store object in old generation 
Copyright © GREE, Inc. All Rights Reserved. 
Full GC 
Young generation Old generation 
43/56
Copyright © GREE, Inc. All Rights Reserved. 
Causes of Uncollected 
Reference Problem 
• Use method that has side effects 
• Reuse object everywhere 
• Forget to release used resources 
44/56
Copyright © GREE, Inc. All Rights Reserved. 
Causes of Uncollected 
Reference Problem 
• Use method that has side effects 
• Reuse object everywhere 
• Forget to release used resources 
Difficult to recognize by developers 
45/56
Copyright © GREE, Inc. All Rights Reserved. 
Short-Lived Object 
• Use val variable (final variable) 
• Don’t use mutable variable 
• Don’t leave references to objects for too long 
Create new objects instead of updating old ones 
46/56
Sharding: Scalable Storage 
47/56 
Copyright © GREE, Inc. All Rights Reserved.
Copyright © GREE, Inc. All Rights Reserved. 
Scale up? 
48/56
Copyright © GREE, Inc. All Rights Reserved. 
Scale out! 
49/56
Copyright © GREE, Inc. All Rights Reserved. 
Horizontal Partitioning 
• Sharding is necessary! 
• Considering capacity and #accesses 
• We have Cascade, a sharding library 
• For PHP, not Scala 
• So, we created Aurora and make it OSS 
• Aurora and application were developed 
simultaneously 
• So difficult to integrate them during 
development 
• Code modification must be done in many parts 
50/56
ID Architecture: 
UUID and InnoDB 
Ref:MySQL InnoDB Primary Key Choice: GUID/UUID vs Integer Insert Performance 
http://kccoder.com/mysql/uuid-vs-int-insert-performance/ 
Copyright © GREE, Inc. All Rights Reserved.
Ref:MySQL InnoDB Primary Key Choice: GUID/UUID vs Integer Insert Performance 
http://kccoder.com/mysql/uuid-vs-int-insert-performance/ 
Copyright © GREE, Inc. All Rights Reserved. 
UUID 
AUTO_INCREMENT #record 
#time
Drop UUID, Take Time-Based 
• At first, we used UUID as primary key 
• But this caused MySQL to insert randomly 
• Created a library to generate ID instead 
• Referred to Snowflake by Twitter 
• Sequential insertion based on sorted created 
time 
53/56 
Copyright © GREE, Inc. All Rights Reserved.
Copyright © GREE, Inc. All Rights Reserved. 
Summary: Obstacles & 
Workaround 
• JVM 
• Use short-lived objects to avoid Full GC 
• Self-created Scala library 
• Sharding 
• Made Scala library OSS 
• Integration of library to application was difficult 
• ID Architecture 
• Adopt time-based ID for sequential insertion 
54/56
Copyright © GREE, Inc. All Rights Reserved. 
Outline 
• Reason of Selecting Scala 
• Learning Scala in a Team 
• Architecture of GREE Chat 
• Obstacles 
• Summary
Copyright © GREE, Inc. All Rights Reserved. 
Summary 
• Reasons for selecting Scala 
• Compatible with concurrent programming 
• Plan Scala learning within the team 
• Learning cost is expensive 
• Architecture & Frameworks 
• Each server is separated by Queue 
• Finagle, Akka 
• Shortage of libraries 
• We must have made libraries by ourselves 
• Needed to pull request to OSS repository 
56/56
Copyright © GREE, Inc. All Rights Reserved. 
Thanks! 
@tomoyoshi_ogura, @kyo_ago, @takc923 
@yoshie_777, @le_chang, @beketa, @j5ik2o 
and 
ScalaMatsuri staffs

More Related Content

What's hot (20)

PDF
deep learning in production cff 2017
Ari Kamlani
 
PPTX
Apache Spark: Usage and Roadmap in Hadoop
Cloudera Japan
 
PDF
Development with JavaFX 9 in JDK 9.0.1
Wolfgang Weigend
 
PDF
The Kubernetes WebLogic revival (part 2)
Simon Haslam
 
PDF
What's New in IBM Java 8 SE?
Tim Ellison
 
PPTX
The do's and don'ts with java 9 (Devoxx 2017)
Robert Scholte
 
PDF
Dockerizing Oracle Database
gvenzl
 
PDF
Hadoop {Submarine} Project: Running Deep Learning Workloads on YARN
DataWorks Summit
 
PDF
Cloud Native Java:GraalVM
Taewan alvin Kim
 
PDF
Extending Build to the Client: A Maven User's Guide to Grunt.js
Petr Jiricka
 
KEY
Enterprise Architectures with Ruby (and Rails)
Konstantin Gredeskoul
 
PDF
Polyglot Plugin Programming
Atlassian
 
PDF
Supercharge your Code to get optimal Database Performance
gvenzl
 
PPTX
Apache Spark Operations
Cloudera, Inc.
 
PPTX
Cloud Spanner をより便利にする運用支援ツールの紹介
gree_tech
 
PPTX
Java 9 Functionality and Tooling
Trisha Gee
 
PDF
Wicked Easy Ceph Block Storage & OpenStack Deployment with Crowbar
Kamesh Pemmaraju
 
PPTX
Splunk Java Agent
Damien Dallimore
 
PDF
Rich Archbold, Senior Director of Engineering, Intercom - Run less software
Techsylvania
 
PDF
Ventajas de IPv6
Eduardo Castro
 
deep learning in production cff 2017
Ari Kamlani
 
Apache Spark: Usage and Roadmap in Hadoop
Cloudera Japan
 
Development with JavaFX 9 in JDK 9.0.1
Wolfgang Weigend
 
The Kubernetes WebLogic revival (part 2)
Simon Haslam
 
What's New in IBM Java 8 SE?
Tim Ellison
 
The do's and don'ts with java 9 (Devoxx 2017)
Robert Scholte
 
Dockerizing Oracle Database
gvenzl
 
Hadoop {Submarine} Project: Running Deep Learning Workloads on YARN
DataWorks Summit
 
Cloud Native Java:GraalVM
Taewan alvin Kim
 
Extending Build to the Client: A Maven User's Guide to Grunt.js
Petr Jiricka
 
Enterprise Architectures with Ruby (and Rails)
Konstantin Gredeskoul
 
Polyglot Plugin Programming
Atlassian
 
Supercharge your Code to get optimal Database Performance
gvenzl
 
Apache Spark Operations
Cloudera, Inc.
 
Cloud Spanner をより便利にする運用支援ツールの紹介
gree_tech
 
Java 9 Functionality and Tooling
Trisha Gee
 
Wicked Easy Ceph Block Storage & OpenStack Deployment with Crowbar
Kamesh Pemmaraju
 
Splunk Java Agent
Damien Dallimore
 
Rich Archbold, Senior Director of Engineering, Intercom - Run less software
Techsylvania
 
Ventajas de IPv6
Eduardo Castro
 

Viewers also liked (20)

PDF
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp
 
PDF
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
PDF
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
scalaconfjp
 
PDF
Solid And Sustainable Development in Scala
Kazuhiro Sera
 
PDF
The Evolution of Scala / Scala進化論
scalaconfjp
 
PDF
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
scalaconfjp
 
PDF
Scalable Generator: Using Scala in SIer Business (ScalaMatsuri)
TIS Inc.
 
PDF
GitBucket: The perfect Github clone by Scala
takezoe
 
PDF
sbt, past and future / sbt, 傾向と対策
scalaconfjp
 
PPTX
From Ruby to Scala
tod esking
 
PDF
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Taro L. Saito
 
PPTX
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
scalaconfjp
 
PDF
Node.js vs Play Framework (with Japanese subtitles)
Yevgeniy Brikman
 
PDF
Scala@SmartNews AdFrontend を Scala で書いた話
Keiji Muraishi
 
PDF
Scalaの現状と今後
Kota Mizushima
 
PDF
芸者東京とScala〜おみせやさんから脳トレクエストまでの軌跡〜
scalaconfjp
 
PDF
Scala が支える医療系ウェブサービス #jissenscala
Kazuhiro Sera
 
PDF
Scala@SmartNews_20150221
Shigekazu Takei
 
PDF
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
takezoe
 
PDF
オウンドメディアのコンテンツ事例集40選(サムライト)
サムライト株式会社
 
Scarab: SAT-based Constraint Programming System in Scala / Scala上で実現された制約プログラ...
scalaconfjp
 
Xitrum Web Framework Live Coding Demos / Xitrum Web Framework ライブコーディング
scalaconfjp
 
Introduction to Spark SQL and Catalyst / Spark SQLおよびCalalystの紹介
scalaconfjp
 
Solid And Sustainable Development in Scala
Kazuhiro Sera
 
The Evolution of Scala / Scala進化論
scalaconfjp
 
What's a macro?: Learning by Examples / Scalaのマクロに実用例から触れてみよう!
scalaconfjp
 
Scalable Generator: Using Scala in SIer Business (ScalaMatsuri)
TIS Inc.
 
GitBucket: The perfect Github clone by Scala
takezoe
 
sbt, past and future / sbt, 傾向と対策
scalaconfjp
 
From Ruby to Scala
tod esking
 
Weaving Dataflows with Silk - ScalaMatsuri 2014, Tokyo
Taro L. Saito
 
Building a Unified Data Pipline in Spark / Apache Sparkを用いたBig Dataパイプラインの統一
scalaconfjp
 
Node.js vs Play Framework (with Japanese subtitles)
Yevgeniy Brikman
 
Scala@SmartNews AdFrontend を Scala で書いた話
Keiji Muraishi
 
Scalaの現状と今後
Kota Mizushima
 
芸者東京とScala〜おみせやさんから脳トレクエストまでの軌跡〜
scalaconfjp
 
Scala が支える医療系ウェブサービス #jissenscala
Kazuhiro Sera
 
Scala@SmartNews_20150221
Shigekazu Takei
 
ビズリーチの新サービスをScalaで作ってみた 〜マイクロサービスの裏側 #jissenscala
takezoe
 
オウンドメディアのコンテンツ事例集40選(サムライト)
サムライト株式会社
 
Ad

Similar to [ScalaMatsuri] グリー初のscalaプロダクト!チャットサービス公開までの苦労と工夫 (20)

PDF
Scala - from "Hello, World" to "Heroku Scale"
Salesforce Developers
 
PPTX
Introduction to Scala
Mohammad Hossein Rimaz
 
PPTX
Scala adoption by enterprises
Mike Slinn
 
PPT
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
PDF
Reactive Software Systems
Behrad Zari
 
KEY
The Why and How of Scala at Twitter
Alex Payne
 
PPTX
Indic threads pune12-typesafe stack software development on the jvm
IndicThreads
 
PDF
The Ring programming language version 1.10 book - Part 6 of 212
Mahmoud Samir Fayed
 
PDF
Scala, Akka, and Play: An Introduction on Heroku
Havoc Pennington
 
PDF
Quick introduction to scala
Mohammad Hossein Rimaz
 
PDF
The Ring programming language version 1.9 book - Part 6 of 210
Mahmoud Samir Fayed
 
PDF
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
KEY
Scala Introduction
Adrian Spender
 
PDF
Whitepages Practical Experience Converting from Ruby to Reactive
Dragos Manolescu
 
PDF
The Ring programming language version 1.5.3 book - Part 5 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 5 of 185
Mahmoud Samir Fayed
 
PPT
Writing DSL's in Scala
Abhijit Sharma
 
PDF
Scala services in action
Underscore
 
PDF
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
PDF
An Introduction to Scala for Java Developers
Miles Sabin
 
Scala - from "Hello, World" to "Heroku Scale"
Salesforce Developers
 
Introduction to Scala
Mohammad Hossein Rimaz
 
Scala adoption by enterprises
Mike Slinn
 
Introducing Scala to your Ruby/Java Shop : My experiences at IGN
Manish Pandit
 
Reactive Software Systems
Behrad Zari
 
The Why and How of Scala at Twitter
Alex Payne
 
Indic threads pune12-typesafe stack software development on the jvm
IndicThreads
 
The Ring programming language version 1.10 book - Part 6 of 212
Mahmoud Samir Fayed
 
Scala, Akka, and Play: An Introduction on Heroku
Havoc Pennington
 
Quick introduction to scala
Mohammad Hossein Rimaz
 
The Ring programming language version 1.9 book - Part 6 of 210
Mahmoud Samir Fayed
 
Typesafe stack - Scala, Akka and Play
Luka Zakrajšek
 
Scala Introduction
Adrian Spender
 
Whitepages Practical Experience Converting from Ruby to Reactive
Dragos Manolescu
 
The Ring programming language version 1.5.3 book - Part 5 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 5 of 185
Mahmoud Samir Fayed
 
Writing DSL's in Scala
Abhijit Sharma
 
Scala services in action
Underscore
 
BCS SPA 2010 - An Introduction to Scala for Java Developers
Miles Sabin
 
An Introduction to Scala for Java Developers
Miles Sabin
 
Ad

More from gree_tech (20)

PPTX
アナザーエデンPC版リリースへの道のり 〜WFSにおけるマルチプラットフォーム対応の取り組み〜
gree_tech
 
PDF
GREE VR Studio Laboratory「XR-UX Devプロジェクト」の成果紹介
gree_tech
 
PPTX
REALITYアバターを様々なメタバースで活躍させてみた - GREE VR Studio Laboratory インターン研究成果発表
gree_tech
 
PPTX
アプリ起動時間高速化 ~推測するな、計測せよ~
gree_tech
 
PPTX
長寿なゲーム事業におけるアプリビルドの効率化
gree_tech
 
PPTX
WFSにおけるCloud SpannerとGKEを中心としたGCP導入事例の紹介
gree_tech
 
PPTX
SINoALICE -シノアリス- Google Cloud Firestoreを用いた観戦機能の実現について
gree_tech
 
PPTX
海外展開と負荷試験
gree_tech
 
PPTX
翻訳QAでのテスト自動化の取り組み
gree_tech
 
PPTX
組み込み開発のテストとゲーム開発のテストの違い
gree_tech
 
PPTX
サーバーフレームワークに潜んでる脆弱性検知ツール紹介
gree_tech
 
PPTX
データエンジニアとアナリストチーム兼務になった件について
gree_tech
 
PPTX
シェアドサービスとしてのデータテクノロジー
gree_tech
 
PPTX
「ドキュメント見つからない問題」をなんとかしたい - 横断検索エンジン導入の取り組みについて-
gree_tech
 
PPTX
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
gree_tech
 
PPTX
比較サイトの検索改善(SPA から SSR に変換)
gree_tech
 
PPTX
コードの自動修正によって実現する、機能開発を止めないフレームワーク移行
gree_tech
 
PPTX
「やんちゃ、足りてる?」〜ヤンマガWebで挑戦を続ける新入りエンジニア〜
gree_tech
 
PPTX
法人向けメタバースプラットフォームの開発の裏側をのぞいてみた(仮)
gree_tech
 
PPTX
基調講演 -グリーが目指すエンジニアのあり方、チームのあり方-
gree_tech
 
アナザーエデンPC版リリースへの道のり 〜WFSにおけるマルチプラットフォーム対応の取り組み〜
gree_tech
 
GREE VR Studio Laboratory「XR-UX Devプロジェクト」の成果紹介
gree_tech
 
REALITYアバターを様々なメタバースで活躍させてみた - GREE VR Studio Laboratory インターン研究成果発表
gree_tech
 
アプリ起動時間高速化 ~推測するな、計測せよ~
gree_tech
 
長寿なゲーム事業におけるアプリビルドの効率化
gree_tech
 
WFSにおけるCloud SpannerとGKEを中心としたGCP導入事例の紹介
gree_tech
 
SINoALICE -シノアリス- Google Cloud Firestoreを用いた観戦機能の実現について
gree_tech
 
海外展開と負荷試験
gree_tech
 
翻訳QAでのテスト自動化の取り組み
gree_tech
 
組み込み開発のテストとゲーム開発のテストの違い
gree_tech
 
サーバーフレームワークに潜んでる脆弱性検知ツール紹介
gree_tech
 
データエンジニアとアナリストチーム兼務になった件について
gree_tech
 
シェアドサービスとしてのデータテクノロジー
gree_tech
 
「ドキュメント見つからない問題」をなんとかしたい - 横断検索エンジン導入の取り組みについて-
gree_tech
 
「Atomic Design × Nuxt.js」コンポーネント毎に責務の範囲を明確にしたら幸せになった話
gree_tech
 
比較サイトの検索改善(SPA から SSR に変換)
gree_tech
 
コードの自動修正によって実現する、機能開発を止めないフレームワーク移行
gree_tech
 
「やんちゃ、足りてる?」〜ヤンマガWebで挑戦を続ける新入りエンジニア〜
gree_tech
 
法人向けメタバースプラットフォームの開発の裏側をのぞいてみた(仮)
gree_tech
 
基調講演 -グリーが目指すエンジニアのあり方、チームのあり方-
gree_tech
 

Recently uploaded (20)

PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
OpenID AuthZEN - Analyst Briefing July 2025
David Brossard
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
HubSpot Main Hub: A Unified Growth Platform
Jaswinder Singh
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 

[ScalaMatsuri] グリー初のscalaプロダクト!チャットサービス公開までの苦労と工夫

  • 1. The Trial and Error in Releasing GREE Chat Shun Ozaki, Takayuki Hasegawa Copyright © GREE, Inc. All Rights Reserved. Scala Matsuri2014 B-6 GREE's First Scala Product
  • 2. Copyright © GREE, Inc. All Rights Reserved. Self Introduction • Shun Ozaki • @wozaki • Joined in April, 2013 • Android Application • Takayuki Hasegawa • @hase1031 • Joined in April, 2013 • NLP, Machine Learning 1/56
  • 3. Copyright © GREE, Inc. All Rights Reserved. GREE Chat • Released at June 2 2/56
  • 4. How to build our system for hundreds of thousands daily users Copyright © GREE, Inc. All Rights Reserved. Agenda 3/56
  • 5. Goal Share our knowledge we got through the development of GREE Chat Copyright © GREE, Inc. All Rights Reserved. • Why Scala? • Team development • Decision of frameworks • Obstacles & workarounds 4/56
  • 6. Copyright © GREE, Inc. All Rights Reserved. Outline • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary
  • 7. • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary Copyright © GREE, Inc. All Rights Reserved. Outline
  • 8. Decide the Language based on the Requirement Copyright © GREE, Inc. All Rights Reserved.
  • 9. Requirements • Hundreds of thousands daily users • Real-time response Copyright © GREE, Inc. All Rights Reserved.  Connect with streaming • Run on a small number of servers  Utilize server resource effectively • Maintain for over 5 years 8/56
  • 10. Copyright © GREE, Inc. All Rights Reserved. ◎ GREE uses PHP so heavily • Many libraries and know-how in GREE △ Streaming • #connections = #processes △ Single thread, multi process • Overhead of spawning an OS process △ Maintainability • Dynamic typing 9/56
  • 11. ◎Compatible with concurrent programming ◎One process, many connections ◎High maintainability • Static typing • Functional programming (no side effects) ◎Stimulate new technology learning in GREE • Open to new languages & technologies! Copyright © GREE, Inc. All Rights Reserved. Scala! 10/56
  • 12. • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary Copyright © GREE, Inc. All Rights Reserved. Outline
  • 13. After adopting Scala … Copyright © GREE, Inc. All Rights Reserved.
  • 14. Only two Scala programmers in a team of seven Copyright © GREE, Inc. All Rights Reserved. Shortage of Scala experts 2/ 7 13/56
  • 15. Only two Scala programmers in a team of seven We must build up our skill! Copyright © GREE, Inc. All Rights Reserved. Shortage of Scala experts 2/ 7 14/56
  • 16. Copyright © GREE, Inc. All Rights Reserved. Learning of Scala 1. Self study 2. Study club 3. Pair programming 15/56
  • 17. Copyright © GREE, Inc. All Rights Reserved. 1. Self Study Understand the basic syntax
  • 18. Copyright © GREE, Inc. All Rights Reserved. 1. Self Study Books 17/56
  • 19. Copyright © GREE, Inc. All Rights Reserved. 1. Self Study Documents by Twitter https://twitter.github.io/scala_school/ http://twitter.github.io/effectivescala/ 18/56
  • 20. Copyright © GREE, Inc. All Rights Reserved. 1. Self Study Source code from OSS 19/56
  • 21. Copyright © GREE, Inc. All Rights Reserved. 2. Study Club Share what we learned by ourselves Introduction to functional programming
  • 22. 2. Study Club • Each engineer solves the problems provided by Scala experts Copyright © GREE, Inc. All Rights Reserved. • e.g., Binary Tree, Fibonacci Sequence 21/56
  • 23. • Example of factorial generation algorithm Copyright © GREE, Inc. All Rights Reserved. 2. Study Club Discussion with Members Use var Use recursion 22/56
  • 24. • Example of factorial generation algorithm Use var Use recursion Copyright © GREE, Inc. All Rights Reserved. 2. Study Club Discussion with Members No side effect 23/56
  • 25. 3. Pair Programming Practice by using the knowledge Copyright © GREE, Inc. All Rights Reserved. obtained from study club
  • 26. Copyright © GREE, Inc. All Rights Reserved. 3. Pair Programming • Effective learning • Learn about symbols (e.g., +, @), which cannot be searched easily on the Internet • Supplement the knowledge not taught at study club • Complex syntaxes (e.g., implicit, currying) • Development tools (e.g., sbt, IntelliJ) 25/56
  • 27. Copyright © GREE, Inc. All Rights Reserved. Summary: Adopting Scala • Reasons of selecting Scala • Compatible with concurrent programming • Maintainability because of static typing • Learning of Scala • Self Study, Study Club, Pair Programming • Big burdens on Scala experts • Needed for teaching team members • Maintain the quality of codes 26/56
  • 28. • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary Copyright © GREE, Inc. All Rights Reserved. Outline
  • 29. Architecture of Backend (simplified) Copyright © GREE, Inc. All Rights Reserved. • Servers separated by Queues • API Server: Process users’ requests • EventBus Server: Process events in Queue • Stream Server: Supply event to connected users 28/56
  • 30. Role of Each Server Copyright © GREE, Inc. All Rights Reserved. and Framework
  • 31. Copyright © GREE, Inc. All Rights Reserved. API Server Process users’ requests • Enqueue events • e.g., Send message Join/leave conversation • Techniques to process a lot of requests • Delegate heavy tasks (e.g., Disk I/O) to others • Logic is written to run asynchronously • scala.concurrent.Future 30/56
  • 32. • RPC system for JVM based on Netty • Support us to write asynchronous logic Copyright © GREE, Inc. All Rights Reserved. • Used by large scale web services • e.g., Twitter, Tumblr, Foursquare, Pinterest • Equipped with various clients • Redis, Memcached • With retry policy, connection pools 31/56
  • 33. Copyright © GREE, Inc. All Rights Reserved. EventBus Server Process events in Queue • Examples of tasks • Logging • Inquire GREE internal system • Store events in DB • etc. • Problems of concurrent processing • Deadlock, race condition, … 32/56
  • 34. Framework to write concurrent, distributed logic more easily • No need to handle shared resources Copyright © GREE, Inc. All Rights Reserved. • Race condition, dead-lock • Logic separation • Parent-Child • Fault tolerance 33/56
  • 35. Copyright © GREE, Inc. All Rights Reserved. Example of Akka 34/56
  • 36. Copyright © GREE, Inc. All Rights Reserved. Example of Akka Match by Event type 35/56
  • 37. Copyright © GREE, Inc. All Rights Reserved. Example of Akka Send copy to child 36/56
  • 38. Copyright © GREE, Inc. All Rights Reserved. Example of Akka log 37/56
  • 39. Copyright © GREE, Inc. All Rights Reserved. Stream Server Supply events to connected users • Connect by streaming • Increase connections as much as possible • Keep users data in the memory to reduce I/O • Asynchronous I/O by Finagle, Akka • Task division by Akka • Supply events to users • Update users data • Send KeepAlive to users 38/56
  • 40. Copyright © GREE, Inc. All Rights Reserved. Summary: Architecture • Each server is separated by Queue • API, EventBus, Stream Server • Framework is selected by considering asynchronous processing • Finagle, Akka • Task is divided by Akka • Easy to write concurrent logic 39/56
  • 41. Copyright © GREE, Inc. All Rights Reserved. Outline • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary
  • 42. Copyright © GREE, Inc. All Rights Reserved. Obstacles 1.JVM • Full GC 2. Self-created Scala library • Sharding • ID Architecture 41/56
  • 43. Full GC Problems Copyright © GREE, Inc. All Rights Reserved.
  • 44. • Scala runs on JVM • We want to prevent “stop the world” • GC in young generation is faster than full GC • Try not to let it store object in old generation Copyright © GREE, Inc. All Rights Reserved. Full GC Young generation Old generation 43/56
  • 45. Copyright © GREE, Inc. All Rights Reserved. Causes of Uncollected Reference Problem • Use method that has side effects • Reuse object everywhere • Forget to release used resources 44/56
  • 46. Copyright © GREE, Inc. All Rights Reserved. Causes of Uncollected Reference Problem • Use method that has side effects • Reuse object everywhere • Forget to release used resources Difficult to recognize by developers 45/56
  • 47. Copyright © GREE, Inc. All Rights Reserved. Short-Lived Object • Use val variable (final variable) • Don’t use mutable variable • Don’t leave references to objects for too long Create new objects instead of updating old ones 46/56
  • 48. Sharding: Scalable Storage 47/56 Copyright © GREE, Inc. All Rights Reserved.
  • 49. Copyright © GREE, Inc. All Rights Reserved. Scale up? 48/56
  • 50. Copyright © GREE, Inc. All Rights Reserved. Scale out! 49/56
  • 51. Copyright © GREE, Inc. All Rights Reserved. Horizontal Partitioning • Sharding is necessary! • Considering capacity and #accesses • We have Cascade, a sharding library • For PHP, not Scala • So, we created Aurora and make it OSS • Aurora and application were developed simultaneously • So difficult to integrate them during development • Code modification must be done in many parts 50/56
  • 52. ID Architecture: UUID and InnoDB Ref:MySQL InnoDB Primary Key Choice: GUID/UUID vs Integer Insert Performance http://kccoder.com/mysql/uuid-vs-int-insert-performance/ Copyright © GREE, Inc. All Rights Reserved.
  • 53. Ref:MySQL InnoDB Primary Key Choice: GUID/UUID vs Integer Insert Performance http://kccoder.com/mysql/uuid-vs-int-insert-performance/ Copyright © GREE, Inc. All Rights Reserved. UUID AUTO_INCREMENT #record #time
  • 54. Drop UUID, Take Time-Based • At first, we used UUID as primary key • But this caused MySQL to insert randomly • Created a library to generate ID instead • Referred to Snowflake by Twitter • Sequential insertion based on sorted created time 53/56 Copyright © GREE, Inc. All Rights Reserved.
  • 55. Copyright © GREE, Inc. All Rights Reserved. Summary: Obstacles & Workaround • JVM • Use short-lived objects to avoid Full GC • Self-created Scala library • Sharding • Made Scala library OSS • Integration of library to application was difficult • ID Architecture • Adopt time-based ID for sequential insertion 54/56
  • 56. Copyright © GREE, Inc. All Rights Reserved. Outline • Reason of Selecting Scala • Learning Scala in a Team • Architecture of GREE Chat • Obstacles • Summary
  • 57. Copyright © GREE, Inc. All Rights Reserved. Summary • Reasons for selecting Scala • Compatible with concurrent programming • Plan Scala learning within the team • Learning cost is expensive • Architecture & Frameworks • Each server is separated by Queue • Finagle, Akka • Shortage of libraries • We must have made libraries by ourselves • Needed to pull request to OSS repository 56/56
  • 58. Copyright © GREE, Inc. All Rights Reserved. Thanks! @tomoyoshi_ogura, @kyo_ago, @takc923 @yoshie_777, @le_chang, @beketa, @j5ik2o and ScalaMatsuri staffs

Editor's Notes

  • #2: 前半のプレゼンは 私が担当 後半 長谷川が担当 グリーで初めてのScalaプロダクト チャットサービスを作った リリースするまでの苦労や工夫について 30分
  • #3: 2013年に入社 それから チャットのバックエンド開発に参加している 大学時代はAndroidアプリケーションの開発 フロントエンジニアより
  • #4: 本日話すGREEチャットの画面例 動作のイメージは、 ざっくり言うと、GREEユーザ同士で会話できるLINE LINEさんが来ている前で こんなこと言うと怒られるかもしれませんが GREE Chatを作った目的 リアルタイムのコミュニケーションで、ユーザのアクティビティを活性化させるという目的
  • #5: 本日話す内容 数十万人の利用を想定するチャットのバックエンド Scalaでどのように構築したか
  • #6: このプレゼンのゴール 主な対象者=>これからScalaでプロダクトを構築する人 今回バックエンドをScalaで構築するにあたって得た知見の共有 具体的には 1.なぜScalaを選んだか 2 Scalaを利用して、どのようにチームで開発したか 3 どのようなシステム構成でどのようなフレームワークを選定したか 4 開発で苦労したこと、解決策
  • #8: Scalaを選んだ理由
  • #9: 言語を選定するにあたって、GREEチャットの要件から決めました
  • #10: 主な要件は4つ 1. 数十万の利用者を想定 2. チャット特有のリアルタイムなレスポンス 何千もストリーミングで同時接続できること 3. 少ないサーバ台数で稼働すること、コスト削減 =>サーバの資源を効率的に活用できる言語であるということが求められる 4. 5年以上の保守
  • #11: まず白羽の矢がたったのがPHP GREEの主要言語はPHP ->社内にライブラリや運用ノウハウがたくさんある 今回の要件に適さない問題が3つ(PHP disではない) 1 ストリーミング 接続数分だけプロセス数が必要 -> 何千とか接続してきたときにプロセスを立ち上げるのは辛い 2 基本的にシングルスレッド -> プロセス起動のオーバーヘッドが発生する -> サーバCPUを効率的に利用 難しい 3 保守性 ・動的型付け言語 => ある程度の規模になると、保守難しくなる その他:セミコロンが無い
  • #12: そこでScalaを採用しました 1.並行プログラミングとの親和性 -> CPUを効率よく使える -> サーバ台数少なくてすむ 2.一つのプロセスで複数のコネクション 3.保守性(静的型付け言語、関数型言語の特徴があるので、副作用がない関数をつくりやすい=>バグを生みにくい) 4.社内技術の活性化 (一つの言語に縛られないこと、) Javaと比較 短いコードの記述量 他にも細かいところ 色々あるが、決めてScalaが大好きなエンジニアがいたからScala
  • #13: どのようにチームでScalaを学んで言ったかについてお話します
  • #14: Scalaを採用したのはいいんですが
  • #15: Scalaの経験者は不足していました チーム7人中二人
  • #16: チームでScala力向上の必要
  • #17: 学習のコンテンツは3つです 1 自主学習 2 チームでの勉強会 3 経験者とペアプロ
  • #18: 目的:基本手な構文の理解 Scalaはどういった特徴
  • #19: 1 Programming in Scala (通称コップ本 言語設計上の話など詳細 1度に全部理解するのは困難だが、 何度も見返す Scala逆引きレシピ リファレンスとして手元に置いておく webの問題点として、回答の質がばらついている 逆引きリファレンスは質も網羅性も高い 著者が全員 登壇しているが、よいしょでも やらせでもなく
  • #20: Scala School コンソールで動きを確かめながら 手を動かしながら進めやすい Effective Scala コードのフォーマットからエラーハンドルまで、Twitterのscalaノウハウがあるので参考にしている
  • #21: Scalaのライブラリは、基本的にGithub上に公開されている Twittreの中の人が、どんなscalaコードを書いているかなど分かる 参考に
  • #22: 勉強会 目的:  個々の学びをチームで共有、 関数型プログラミングの入門
  • #23: Scala経験者が提供する練習問題作成 チームで問題を解く 二分木、フィボナッチ数列など
  • #24: できた回答をチームメンバーで共有し議論する 階乗計算の答えを2つ載せる 1 var 再代入可能な変数とforループを使用 2 再帰
  • #25: varを利用している方は、ループの中で再代入しているのが分かる 再帰: データの破壊的代入はしていな varのように後から変更可能な変数の利用 -> 自分が想定していない箇所で変更される可能性がある -> バグの元 (規模が大きくなってくるときつい) ◆チームの方針: 必要最小限の副作用で構成されたコードを目指す => 保守性を維持
  • #26: ペアプロ 経験者のサポートありで、 自主学習や勉強会で得た知識を実践で活用
  • #27: 利点 1.効果的な学習 記号が使われているがwebで検索できない問題->人に聞くのが早い Scalaでは様々な書き方できるが故に結局どう書いていいのか混乱 2.勉強会で補えないものを補足する a 難解な構文、implicit やカリー化、 なんでもかんでもimplicitにすればいいものじゃない b コード以外で言うと、sbtやIntelliJの効果的な使い方の共有 午前中に横田さんのsbtで一緒にやった方
  • #28: Scalaを選んだ理由 1 並行プログラミングと親和性高い 2 コードの保守性高い  静的型付け言語や副作用の無い関数型プロミングができるので Scalaの初期学習コストは、それなりにある ・自主学習、勉強会、ペアプロ ・チームで取り組む Scala経験者には負荷はかかる ・Scakaのノウハウの布教、コードのクオリティを保つためのコードレビュー
  • #29: GREEチャットのアーキテクチャ
  • #30: バックエンドの簡略図 青:アプリケーションサーバ、赤;Q Qで別れている。 CPUバウンド=>サーバ台数を増やすことでスケーリングすることが可能 API Server: ユーザのリクエストを受け付け 処理 EventBus Server: Qからデータを取得・加工 Stream Server: 接続しているユーザへデータを流す
  • #31: 各サーバの役割詳細 そこで利用しているフレームワークを紹介
  • #32: ユーザのリクエストを処理する Eventをエンキュー Event:メッセージの送信、会話の参加、離脱 大量のリクエストを捌く工夫 1.重い処理、例えばDisl I/Oは キューイングして 他のサーバへ委譲 ->ユーザのリクエストの受付に専念 2.ロジックは基本的に非同期処理(scalaのFutureライブラリを利用している)
  • #33: Finagle NettyをベースのRPCフレームワーク Twitter社が提供している、 非同期前提でアクションを書きやすい 2 他の大規模webサービスの事例もある ・Twitter, Tublr, Foursquare, Pinterest 3 サーバだけで無くクライアントも提供している Redis、Memcacheクライアントにも利用してる
  • #34: Qに積まれたEventの処理 例 ログ出力 GREE内部システムへ問い合わせ DBにstore等.. 複雑な処理を並行で効率良く捌く際の問題点 デッドロック、競合
  • #35: 並行・分散処理をより簡単に書くためのフレームワーク 特徴は3つ 1 共有データを処理する必要がない=> 競合、デッドロックで悩むことが無い 2 ロジックを親と子で階層構造で分けることができ、ロジックの分離・分散させやすい 3 耐障害性
  • #36: コードを使って、 Akkaが何故、並行処理をやりやすいか説明します 上と下は親子関係になっている 親はEventを子に割り振る 子はEventをログに出力する
  • #37: まず親が受け取ったEventの中から、 種類によって処理を変えます 赤線で囲まれた処理を説明していきます
  • #38: 子にEventを送る Eventはコピーされたもの =>共有オブジェクトの管理から解放されます
  • #39: 受け取った子はログに出力する これをデッドロックや競合なしで、並行で複数走っている
  • #40: 接続しているユーザへEventをStreamで送信している 接続数をできるだけ増やす工夫 1. ユーザ情報をメモリ上で管理している。Disk I/Oを減らしている 2. AkkaやFinagleを利用した非同期処理をここでも利用 Eventbus同様にいくつかの処理をAkkaで処理している 1 Eventをユーザへ送信 2 ユーザ情報の更新 3 KeepAliveの送信
  • #41: アーキテクチャの特徴としてQによってアプリケーションサーバを分けている フレームワークはFinagle,Akka,を採用している
  • #42: ここからは長谷川がお話します
  • #44: Gangliaというソフトウェアでヒープ領域を計測していたときの実際のグラフです。 左側が急上昇しているのはプログラムに一つおかしなところがあったからで、そこを修正してからは右側のように平穏で、リリース後は一度もFullGCが起きていません。 そこでこれからどのようにFullGCを防いできたかについて話します。
  • #45: FullGCが起こる原理から説明 JVMを使ってるからにはストップザ・ワールドを防ぐ なぜなら、サービスが一時的に停止してしまうから そこで、なるべくYoungでGCを起こすようにしたい もっというなら、Oldにobjectが移動しないようにしたい
  • #46: Old領域にobjectが移動してしまう原因の1つがobjectへの参照が開放されないこと 参照が開放されない原因はいくつかあって 1つ目が、副作用のあるメソッドを使うことです 2つ目が、objectの使い回し 3つ目が、使用したリソースを開放しない
  • #47: これらの原因は開発者が認識することは意外に難しく、日頃から意識しておく必要があります わたしたちのチームでは短命オブジェクトを作るということを心がけてきました
  • #48: 短命オブジェクトとはYoungで回収されるobjectを指す この短命オブジェクトを作るために、基本valを使う Var のようなmutableな変数を極力使わず、長く参照を残さないようにする この例は、チャットの会話情報をDBから引いてきて、それを変更し、保存するコード 全てvalで書かれていることがわかるように、conversationのparticipantIdsのみを部分的に変更するのではなく、新しいobjectを生成する このような工夫を至るところでおこなった結果、FullGCが起きていないことにつながったのではないか 今でも大きな変更を行うときには、jmapで変に参照が残っていないか確認したりしながら運用をしています。
  • #49: Shading分かる? なぜ、shardingをする必要あったか
  • #50: Shading分かる? なぜ、shardingをする必要あったか
  • #51: Shading分かる? なぜ、shardingをする必要あったか
  • #52: グリーチャットのようなI/Oが多く、ユーザーもそれなりに多いサービスになると、ストレージもスレールアウトできるように Sharding、つまりDBの水平分割をする必要があった Cascadeがあったが、PHP用でScala用じゃなかった そこでAuroraを作って、OSS化した ここまで聞くと、おおー、上手くやってるなと思う方もいるかもしれないですが、 実際はアプリケーションの開発とAuroraの開発が同時並行で進んでしまったため、途中でAuroraを組み込む必要がでてきました。 この影響で広範囲にわたって修正する必要があり、これに1ヶ月以上費やしたかと思います。 これはいい教訓になりました
  • #53: 次はUUIDとInnoDBの相性で苦労した話
  • #54: スライドに描かれた図 横軸:100万レコード 縦軸:Insertにかかる時間 緑がUUIDを利用した際のIntertTime Insertの速度が段違い つまり、UUIDをPrimary keyにするのはアンチパターン
  • #55: なんでこんな話をしているかというと、わたしたちがUUIDをPrimary keyとして利用していたから UUIDの悪いところはランダムインサートを引き起こすところ しかし、プログラムの設計上、AUTO_INCREMENTで採番したIDを利用することができない ので、自分たちでID生成ライブラリを作成 TwitterのSnowflakeを参考に 採番したIDは生成時刻でソートできるため、Insertするときにもほぼほぼシーケンシャルになる Snowflakeを使わなかったのは、Zookeeperで専用のID生成サーバーを管理する必要があったため、コストが高い 自分たちで作ったCornflakeというライブラリはもっとlightに使える
  • #56: 苦労したことのまとめ JVM周りではFull GCを起こさないように短命オブジェクトを作るよう意識がけていました ライブラリを自作した話では Shardingライブラリを途中で組み込んで大変だったこと それをOSSにしたこと Snowflakeを参考にしてシーケンシャルインサートできるID生成ライブラリを作成したこと
  • #58: 全体のまとめ Scalaを選んだ理由は、並行プログラミングとの親和性が大きかった チームのScala力向上はコストが高いので、それなりの時間を割いてチーム全体で取り組む必要がある Scalaは他の言語と比べると若い言語なので、ライブラリを自作したり、利用している外部ライブラリにプルリクエストを送るということは当たり前 最後に…