SlideShare ist ein Scribd-Unternehmen logo
1 von 36
SCALA PROFILING
                             (for Java developers)




                                                     Filippo Pacifici


mercoledì 23 maggio 12
Who am I
                    • Filippo Pacifici
                     • Twitter: OddId_
                     • mail: filippo.pacifici@gmail.com
                     • Blog: http://outofmemoryblog.blogspot.com
                    • One of the 9M devs thinking Java is not so bad
                     • recently started looking at Scala
mercoledì 23 maggio 12
What’s this all about?
                    • Apply Java profiling methods to Scala
                         programs
                         • How do we deal with performance in
                           Java?
                         • Is it the same in Scala?
                    • How do we optimize a JVM for Scala
                         applications?


mercoledì 23 maggio 12
Java profiling 101



mercoledì 23 maggio 12
Java profiling 101

                    • Goals:
                     • troubleshoot performance problems
                     • estimate application performance
                     • estimate application scalability

mercoledì 23 maggio 12
Java profiling 101
                    • Ehi, I use Scala, why should I care about Java
                         profiling?
                         • Scala compiled in byte code and runs in a
                           JVM
                         • We can profile a Scala application as it
                           was Java
                         • We can use the same tools
                         • I am not aware of alternatives
mercoledì 23 maggio 12
Java methods profiling
 •      Tracks methods invocations

       •      Runtime instrumentation

       •      Time analysis




mercoledì 23 maggio 12
Java memory profiling
       •      Dumps heap content

             •     Browse objects in the heap

             •     Memory usage analysis




mercoledì 23 maggio 12
Profiling tools
                    • Method profiling
                     • Java Visual VM (embedded in JDK)
                     • Yourkit, Dynatrace, etc.
                    • Memory profiling
                     • Eclipse MAT (www.eclipse.org/
                           mat)
                         • Yourkit, Dynatrace, etc.
mercoledì 23 maggio 12
Back to Scala...

                    • We won’t find Scala specific constructs
                     • Need to know how Scala is translated
                           into bytecode
                    • Goals:
                     • Identify methods generated by Scala
                           compilers
                         • Characterize Scala data structures in
                           memory
mercoledì 23 maggio 12
Scala Functions



mercoledì 23 maggio 12
Short discouraging
                         comparative demo



mercoledì 23 maggio 12
Scala functions vs byte code

                    • Classic functions converted in methods
                    • First class function do not exist in Java
                     • Anonymous classes extending
                           scala.runtime.AbstractFunction
                         • apply method to execute.

mercoledì 23 maggio 12
AbstractFunction
      •     AbstractFunction2

            •     takes 2 input parameters

      •     One apply method per
            combination of input and
            output types

            •     example apply.mcFID

                 •       F= returns float

                 •       I takes one Int

                 •       D takes one Double
mercoledì 23 maggio 12
AbstractFunction
                    • Find the call in the profile:


                • anonfun => instance of the anonymous class
                • main$1 => first anonymous class defined in
                         main method


mercoledì 23 maggio 12
Functions in the heap

                    • Each instance of AbstractFunction present
                         in the heap
                         • Very small impact
                         • Stateless


mercoledì 23 maggio 12
Where do we use them?
                    • Our program did not contain any anonymous
                         function, right?
                    • AbstractFunction used:
                     • For first class functions
                     • For closures
                     • For partially applied functions
                     • To manage for loops blocks
                     • To manage filter logic in for loops
mercoledì 23 maggio 12
Performance impact
                    • Is this a performance impact?
                     • Scala compiler performs optimizations:
                        • Same anonymous functions reused
                           (avoid multiple instantiations)
                         • Anonymous functions doing the same
                           thing are shared
                         • Attention to partially applied:
                          • New function created.
mercoledì 23 maggio 12
Some examples



mercoledì 23 maggio 12
Scala data structures
                             (Collections in heap dump)




mercoledì 23 maggio 12
Scala Lists
                    • A Scala view:
                     • Linked lists (single link)
                     • abstract class List + two case classes: ::
                         and Nil




mercoledì 23 maggio 12
Scala Lists
                    • A byte code view:
                     • Case classes become inner classes:
                       • :: becomes $colon$colon
                       • Nil becomes Nil



mercoledì 23 maggio 12
Scala Lists
                • Heads and elements have the same type




mercoledì 23 maggio 12
Scala Lists

                    • What about mutable lists?
                     • ListBuffer
                       • Wrapper on a Linked List
                       • Keeps an additional reference to the
                          last element: last0



mercoledì 23 maggio 12
Scala Sets
                    • Immutable sets
                     • scala.collection.immutable.Set
                     • Case classes for different sizes
                     • HashSet over 5 elements


mercoledì 23 maggio 12
Scala Maps

                    • Immutable:
                     • small number of elements:
                           scala.collections.immutable.Map$MapN
                         • N = number of elements
                         • over 5 elements:
                           scala.collection.immutable.HashMap
                    • Mutable: scala.collection.mutable.HashMap
mercoledì 23 maggio 12
Map and Sets examples



mercoledì 23 maggio 12
Primitive types boxing



mercoledì 23 maggio 12
Primitive types and
                               generics
                    • Type parameters cannot be primitive in
                         generic types.
                         • Scala systematically boxes and unboxes
                           them to Object
                         • scala.runtime.BoxesRunTime methods


mercoledì 23 maggio 12
Basic tuning tips



mercoledì 23 maggio 12
Exploit tail recursion
                    • Long recursion
                     • Long stack
                     • Performance impact on stack size
                    • Scala compiler recognizes tail recursion
                     • Recursive call must be the last operation
                           of the method
                         • Scala transforms it into iterative form

mercoledì 23 maggio 12
Can’t exploit tail
                               recursion?
                    • If (and only if) you run out of stack space
                         (frequent java.lang.StackOverflowError):
                         • -Xss JVM option sets stack size
                         • example: -Xss2048k
                         • Normally limited at OS level
                         • Each thread statically allocates stack size:
                          • pay attention
mercoledì 23 maggio 12
Memory structure
                    • Optimize for small, short lived objects
                     • Anonymous functions:
                       • small
                       • frequently instantiated
                     • Use a big young space
                       • GC is fast and frequent
                       • Objects do not get promoted
mercoledì 23 maggio 12
Memory structure

                    • What about the perm gen?
                     • Anonymous classes reused
                     • No insane usage of proxies
                     • No specific issues

mercoledì 23 maggio 12
Which GC should I use?
                    • Depends on your application requirements
                     • The same consideration done for Java
                         still hold
                         • Need throughput : parallel GC
                         • Need response time : CMS
                         • You are brave : G1
mercoledì 23 maggio 12
Questions?



mercoledì 23 maggio 12

Weitere ähnliche Inhalte

Was ist angesagt?

クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaShohei Okada
 
コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良くkarupanerura
 
できる!並列・並行プログラミング
できる!並列・並行プログラミングできる!並列・並行プログラミング
できる!並列・並行プログラミングPreferred Networks
 
PHPとブロックチェーンを使ったwebアプリ開発
PHPとブロックチェーンを使ったwebアプリ開発PHPとブロックチェーンを使ったwebアプリ開発
PHPとブロックチェーンを使ったwebアプリ開発Naota Takahashi
 
ソフトウェアテスト入門
ソフトウェアテスト入門ソフトウェアテスト入門
ソフトウェアテスト入門Preferred Networks
 
團隊協作實戰DDD
團隊協作實戰DDD團隊協作實戰DDD
團隊協作實戰DDDJed Lin
 
NAT超えとはなんぞや
NAT超えとはなんぞやNAT超えとはなんぞや
NAT超えとはなんぞやnemumu
 
暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -MITSUNARI Shigeo
 
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)AtCoder Inc.
 
Twitterのsnowflakeについて
TwitterのsnowflakeについてTwitterのsnowflakeについて
Twitterのsnowflakeについてmoai kids
 
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...CODE BLUE
 
Jvm言語とJava、切っても切れないその関係
Jvm言語とJava、切っても切れないその関係Jvm言語とJava、切っても切れないその関係
Jvm言語とJava、切っても切れないその関係yy yank
 
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング MicroAd, Inc.(Engineer)
 
Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Kenjiro Kubota
 
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Taku Miyakawa
 
はりぼて OS で ELF なアプリを起動してみた
はりぼて OS で ELF なアプリを起動してみたはりぼて OS で ELF なアプリを起動してみた
はりぼて OS で ELF なアプリを起動してみたuchan_nos
 
5分でわかるクリーンアーキテクチャ
5分でわかるクリーンアーキテクチャ5分でわかるクリーンアーキテクチャ
5分でわかるクリーンアーキテクチャKenji Tanaka
 

Was ist angesagt? (20)

クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawaクリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
クリーンアーキテクチャの考え方にもとづく Laravel との付き合い方 #phpconokinawa
 
コンテキストと仲良く
コンテキストと仲良くコンテキストと仲良く
コンテキストと仲良く
 
できる!並列・並行プログラミング
できる!並列・並行プログラミングできる!並列・並行プログラミング
できる!並列・並行プログラミング
 
PHPとブロックチェーンを使ったwebアプリ開発
PHPとブロックチェーンを使ったwebアプリ開発PHPとブロックチェーンを使ったwebアプリ開発
PHPとブロックチェーンを使ったwebアプリ開発
 
TLS, HTTP/2演習
TLS, HTTP/2演習TLS, HTTP/2演習
TLS, HTTP/2演習
 
ドロネー三角形分割
ドロネー三角形分割ドロネー三角形分割
ドロネー三角形分割
 
ソフトウェアテスト入門
ソフトウェアテスト入門ソフトウェアテスト入門
ソフトウェアテスト入門
 
團隊協作實戰DDD
團隊協作實戰DDD團隊協作實戰DDD
團隊協作實戰DDD
 
NAT超えとはなんぞや
NAT超えとはなんぞやNAT超えとはなんぞや
NAT超えとはなんぞや
 
暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -暗号文のままで計算しよう - 準同型暗号入門 -
暗号文のままで計算しよう - 準同型暗号入門 -
 
Java8でRDBMS作ったよ
Java8でRDBMS作ったよJava8でRDBMS作ったよ
Java8でRDBMS作ったよ
 
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
実践・最強最速のアルゴリズム勉強会 第一回 講義資料(ワークスアプリケーションズ & AtCoder)
 
Twitterのsnowflakeについて
TwitterのsnowflakeについてTwitterのsnowflakeについて
Twitterのsnowflakeについて
 
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
[CB16] Cyber Grand Challenge (CGC) : 世界初のマシン同士の全自動ハッキングトーナメント by Tyler Nighsw...
 
Jvm言語とJava、切っても切れないその関係
Jvm言語とJava、切っても切れないその関係Jvm言語とJava、切っても切れないその関係
Jvm言語とJava、切っても切れないその関係
 
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング
アドテクに携わって培った アプリをハイパフォーマンスに保つ設計とコーディング
 
Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。Akkaとは。アクターモデル とは。
Akkaとは。アクターモデル とは。
 
Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方Javaのログ出力: 道具と考え方
Javaのログ出力: 道具と考え方
 
はりぼて OS で ELF なアプリを起動してみた
はりぼて OS で ELF なアプリを起動してみたはりぼて OS で ELF なアプリを起動してみた
はりぼて OS で ELF なアプリを起動してみた
 
5分でわかるクリーンアーキテクチャ
5分でわかるクリーンアーキテクチャ5分でわかるクリーンアーキテクチャ
5分でわかるクリーンアーキテクチャ
 

Andere mochten auch

Scala in practice
Scala in practiceScala in practice
Scala in practiceTomer Gabel
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Martin Odersky
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako, Vasil Remeniuk
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascadingjohnynek
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scalaakuklev
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)Yeshwanth Kumar
 
Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話tod esking
 
Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Emprende Futuro
 
Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Sameer Mathur
 
Fyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFranky Redant
 
Despierta Papa Despierta
Despierta Papa DespiertaDespierta Papa Despierta
Despierta Papa Despiertaguesta7eb4a
 
Top 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineTop 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineIAB México
 
Comunicado Numero 1 CIMI
Comunicado Numero 1 CIMIComunicado Numero 1 CIMI
Comunicado Numero 1 CIMIDesarrollo Sena
 
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)humanidadescolapias
 
México 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMéxico 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMarco González
 

Andere mochten auch (20)

Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009Scala Talk at FOSDEM 2009
Scala Talk at FOSDEM 2009
 
Metaprogramming in Scala 2.10, Eugene Burmako,
Metaprogramming  in Scala 2.10, Eugene Burmako, Metaprogramming  in Scala 2.10, Eugene Burmako,
Metaprogramming in Scala 2.10, Eugene Burmako,
 
Scala test
Scala testScala test
Scala test
 
Scalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/CascadingScalding: Twitter's Scala DSL for Hadoop/Cascading
Scalding: Twitter's Scala DSL for Hadoop/Cascading
 
Procedure Typing for Scala
Procedure Typing for ScalaProcedure Typing for Scala
Procedure Typing for Scala
 
RESTful API using scalaz (3)
RESTful API using scalaz (3)RESTful API using scalaz (3)
RESTful API using scalaz (3)
 
Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話Scalaのコンパイルを3倍速くした話
Scalaのコンパイルを3倍速くした話
 
Colaboración y Negocios Web 20
Colaboración y Negocios Web 20Colaboración y Negocios Web 20
Colaboración y Negocios Web 20
 
Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6Creative that cracks the code applied to indian market - Group 6
Creative that cracks the code applied to indian market - Group 6
 
Fyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-slsFyronic seminar-software factorymeeting-sls
Fyronic seminar-software factorymeeting-sls
 
Present redes lvg
Present redes lvgPresent redes lvg
Present redes lvg
 
Despierta Papa Despierta
Despierta Papa DespiertaDespierta Papa Despierta
Despierta Papa Despierta
 
Top 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media OnlineTop 20 TV Online PC-Movil por Garritz Media Online
Top 20 TV Online PC-Movil por Garritz Media Online
 
Felicitación navidad 2013
Felicitación navidad 2013Felicitación navidad 2013
Felicitación navidad 2013
 
Comunicado Numero 1 CIMI
Comunicado Numero 1 CIMIComunicado Numero 1 CIMI
Comunicado Numero 1 CIMI
 
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)Teatro romano de Zaragoza. Cristina Valero (2º bach.)
Teatro romano de Zaragoza. Cristina Valero (2º bach.)
 
LA CRÓNICA 636
LA CRÓNICA 636LA CRÓNICA 636
LA CRÓNICA 636
 
México 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad LoaezaMéxico 1968 orígenes de la transición Soledad Loaeza
México 1968 orígenes de la transición Soledad Loaeza
 
Building TV apps with Chromecast
Building TV apps with ChromecastBuilding TV apps with Chromecast
Building TV apps with Chromecast
 

Ähnlich wie Scala profiling

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Martijn Verburg
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprisesMike Slinn
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin ProgrammingAtlassian
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 dcubeio
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in ScalaAbhijit Sharma
 
Project Lambda, JSR 335
Project Lambda, JSR 335Project Lambda, JSR 335
Project Lambda, JSR 335Martin Skurla
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Martijn Verburg
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Martijn Verburg
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to ScalaBrent Lemons
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLsIndicThreads
 
Java Closures
Java ClosuresJava Closures
Java ClosuresBen Evans
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance TuningBurke Libbey
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Futuremircodotta
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Haim Yadid
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization김 한도
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaJohn Nestor
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Mike Slinn
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeksjutley
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Christopher Haupt
 

Ähnlich wie Scala profiling (20)

Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)Polyglot and functional (Devoxx Nov/2011)
Polyglot and functional (Devoxx Nov/2011)
 
Scala adoption by enterprises
Scala adoption by enterprisesScala adoption by enterprises
Scala adoption by enterprises
 
Polyglot Plugin Programming
Polyglot Plugin ProgrammingPolyglot Plugin Programming
Polyglot Plugin Programming
 
Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217 Scalaマクロ入門 bizr20170217
Scalaマクロ入門 bizr20170217
 
Writing DSL's in Scala
Writing DSL's in ScalaWriting DSL's in Scala
Writing DSL's in Scala
 
Project Lambda, JSR 335
Project Lambda, JSR 335Project Lambda, JSR 335
Project Lambda, JSR 335
 
Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)Introduction to Java 7 (Devoxx Nov/2011)
Introduction to Java 7 (Devoxx Nov/2011)
 
Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)Polyglot and Functional Programming (OSCON 2012)
Polyglot and Functional Programming (OSCON 2012)
 
An Introduction to Scala
An Introduction to ScalaAn Introduction to Scala
An Introduction to Scala
 
Using Scala for building DSLs
Using Scala for building DSLsUsing Scala for building DSLs
Using Scala for building DSLs
 
Java Closures
Java ClosuresJava Closures
Java Closures
 
My sql tutorial-oscon-2012
My sql tutorial-oscon-2012My sql tutorial-oscon-2012
My sql tutorial-oscon-2012
 
Rails Performance Tuning
Rails Performance TuningRails Performance Tuning
Rails Performance Tuning
 
Scala Past, Present & Future
Scala Past, Present & FutureScala Past, Present & Future
Scala Past, Present & Future
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014Concurrency and Multithreading Demistified - Reversim Summit 2014
Concurrency and Multithreading Demistified - Reversim Summit 2014
 
6장 Thread Synchronization
6장 Thread Synchronization6장 Thread Synchronization
6장 Thread Synchronization
 
Experience Converting from Ruby to Scala
Experience Converting from Ruby to ScalaExperience Converting from Ruby to Scala
Experience Converting from Ruby to Scala
 
Composable Futures with Akka 2.0
Composable Futures with Akka 2.0Composable Futures with Akka 2.0
Composable Futures with Akka 2.0
 
Ruby to Scala in 9 weeks
Ruby to Scala in 9 weeksRuby to Scala in 9 weeks
Ruby to Scala in 9 weeks
 
Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)Metaprogramming Primer (Part 1)
Metaprogramming Primer (Part 1)
 

Kürzlich hochgeladen

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 

Scala profiling

  • 1. SCALA PROFILING (for Java developers) Filippo Pacifici mercoledì 23 maggio 12
  • 2. Who am I • Filippo Pacifici • Twitter: OddId_ • mail: filippo.pacifici@gmail.com • Blog: http://outofmemoryblog.blogspot.com • One of the 9M devs thinking Java is not so bad • recently started looking at Scala mercoledì 23 maggio 12
  • 3. What’s this all about? • Apply Java profiling methods to Scala programs • How do we deal with performance in Java? • Is it the same in Scala? • How do we optimize a JVM for Scala applications? mercoledì 23 maggio 12
  • 5. Java profiling 101 • Goals: • troubleshoot performance problems • estimate application performance • estimate application scalability mercoledì 23 maggio 12
  • 6. Java profiling 101 • Ehi, I use Scala, why should I care about Java profiling? • Scala compiled in byte code and runs in a JVM • We can profile a Scala application as it was Java • We can use the same tools • I am not aware of alternatives mercoledì 23 maggio 12
  • 7. Java methods profiling • Tracks methods invocations • Runtime instrumentation • Time analysis mercoledì 23 maggio 12
  • 8. Java memory profiling • Dumps heap content • Browse objects in the heap • Memory usage analysis mercoledì 23 maggio 12
  • 9. Profiling tools • Method profiling • Java Visual VM (embedded in JDK) • Yourkit, Dynatrace, etc. • Memory profiling • Eclipse MAT (www.eclipse.org/ mat) • Yourkit, Dynatrace, etc. mercoledì 23 maggio 12
  • 10. Back to Scala... • We won’t find Scala specific constructs • Need to know how Scala is translated into bytecode • Goals: • Identify methods generated by Scala compilers • Characterize Scala data structures in memory mercoledì 23 maggio 12
  • 12. Short discouraging comparative demo mercoledì 23 maggio 12
  • 13. Scala functions vs byte code • Classic functions converted in methods • First class function do not exist in Java • Anonymous classes extending scala.runtime.AbstractFunction • apply method to execute. mercoledì 23 maggio 12
  • 14. AbstractFunction • AbstractFunction2 • takes 2 input parameters • One apply method per combination of input and output types • example apply.mcFID • F= returns float • I takes one Int • D takes one Double mercoledì 23 maggio 12
  • 15. AbstractFunction • Find the call in the profile: • anonfun => instance of the anonymous class • main$1 => first anonymous class defined in main method mercoledì 23 maggio 12
  • 16. Functions in the heap • Each instance of AbstractFunction present in the heap • Very small impact • Stateless mercoledì 23 maggio 12
  • 17. Where do we use them? • Our program did not contain any anonymous function, right? • AbstractFunction used: • For first class functions • For closures • For partially applied functions • To manage for loops blocks • To manage filter logic in for loops mercoledì 23 maggio 12
  • 18. Performance impact • Is this a performance impact? • Scala compiler performs optimizations: • Same anonymous functions reused (avoid multiple instantiations) • Anonymous functions doing the same thing are shared • Attention to partially applied: • New function created. mercoledì 23 maggio 12
  • 20. Scala data structures (Collections in heap dump) mercoledì 23 maggio 12
  • 21. Scala Lists • A Scala view: • Linked lists (single link) • abstract class List + two case classes: :: and Nil mercoledì 23 maggio 12
  • 22. Scala Lists • A byte code view: • Case classes become inner classes: • :: becomes $colon$colon • Nil becomes Nil mercoledì 23 maggio 12
  • 23. Scala Lists • Heads and elements have the same type mercoledì 23 maggio 12
  • 24. Scala Lists • What about mutable lists? • ListBuffer • Wrapper on a Linked List • Keeps an additional reference to the last element: last0 mercoledì 23 maggio 12
  • 25. Scala Sets • Immutable sets • scala.collection.immutable.Set • Case classes for different sizes • HashSet over 5 elements mercoledì 23 maggio 12
  • 26. Scala Maps • Immutable: • small number of elements: scala.collections.immutable.Map$MapN • N = number of elements • over 5 elements: scala.collection.immutable.HashMap • Mutable: scala.collection.mutable.HashMap mercoledì 23 maggio 12
  • 27. Map and Sets examples mercoledì 23 maggio 12
  • 29. Primitive types and generics • Type parameters cannot be primitive in generic types. • Scala systematically boxes and unboxes them to Object • scala.runtime.BoxesRunTime methods mercoledì 23 maggio 12
  • 31. Exploit tail recursion • Long recursion • Long stack • Performance impact on stack size • Scala compiler recognizes tail recursion • Recursive call must be the last operation of the method • Scala transforms it into iterative form mercoledì 23 maggio 12
  • 32. Can’t exploit tail recursion? • If (and only if) you run out of stack space (frequent java.lang.StackOverflowError): • -Xss JVM option sets stack size • example: -Xss2048k • Normally limited at OS level • Each thread statically allocates stack size: • pay attention mercoledì 23 maggio 12
  • 33. Memory structure • Optimize for small, short lived objects • Anonymous functions: • small • frequently instantiated • Use a big young space • GC is fast and frequent • Objects do not get promoted mercoledì 23 maggio 12
  • 34. Memory structure • What about the perm gen? • Anonymous classes reused • No insane usage of proxies • No specific issues mercoledì 23 maggio 12
  • 35. Which GC should I use? • Depends on your application requirements • The same consideration done for Java still hold • Need throughput : parallel GC • Need response time : CMS • You are brave : G1 mercoledì 23 maggio 12