SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyDaniel Bimschas
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMydbops
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseMike Dirolf
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on Kubernetes[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on KubernetesBruno Borges
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PGConf APAC
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureDan McKinley
 
What every data programmer needs to know about disks
What every data programmer needs to know about disksWhat every data programmer needs to know about disks
What every data programmer needs to know about disksiammutex
 
Hadoop Query Performance Smackdown
Hadoop Query Performance SmackdownHadoop Query Performance Smackdown
Hadoop Query Performance SmackdownDataWorks Summit
 
Writing Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIWriting Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIDatabricks
 
PgTAP Best Practices
PgTAP Best PracticesPgTAP Best Practices
PgTAP Best PracticesDavid Wheeler
 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesRocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesYoshinori Matsunobu
 
Building ZingMe News Feed System
Building ZingMe News Feed SystemBuilding ZingMe News Feed System
Building ZingMe News Feed SystemChau Thanh
 
Understanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitUnderstanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitSpark Summit
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to RedisDvir Volk
 
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GCHadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GCErik Krogen
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger InternalsNorberto Leite
 
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation Buffers
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation BuffersHBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation Buffers
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation BuffersCloudera, Inc.
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB
 

What's hot (20)

Zero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with NettyZero-Copy Event-Driven Servers with Netty
Zero-Copy Event-Driven Servers with Netty
 
MongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To TransactionsMongoDB WiredTiger Internals: Journey To Transactions
MongoDB WiredTiger Internals: Journey To Transactions
 
Inside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source DatabaseInside MongoDB: the Internals of an Open-Source Database
Inside MongoDB: the Internals of an Open-Source Database
 
[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on Kubernetes[Outdated] Secrets of Performance Tuning Java on Kubernetes
[Outdated] Secrets of Performance Tuning Java on Kubernetes
 
Sql Antipatterns Strike Back
Sql Antipatterns Strike BackSql Antipatterns Strike Back
Sql Antipatterns Strike Back
 
PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs PostgreSQL WAL for DBAs
PostgreSQL WAL for DBAs
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
Etsy Activity Feeds Architecture
Etsy Activity Feeds ArchitectureEtsy Activity Feeds Architecture
Etsy Activity Feeds Architecture
 
What every data programmer needs to know about disks
What every data programmer needs to know about disksWhat every data programmer needs to know about disks
What every data programmer needs to know about disks
 
Hadoop Query Performance Smackdown
Hadoop Query Performance SmackdownHadoop Query Performance Smackdown
Hadoop Query Performance Smackdown
 
Writing Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark APIWriting Continuous Applications with Structured Streaming PySpark API
Writing Continuous Applications with Structured Streaming PySpark API
 
PgTAP Best Practices
PgTAP Best PracticesPgTAP Best Practices
PgTAP Best Practices
 
RocksDB Performance and Reliability Practices
RocksDB Performance and Reliability PracticesRocksDB Performance and Reliability Practices
RocksDB Performance and Reliability Practices
 
Building ZingMe News Feed System
Building ZingMe News Feed SystemBuilding ZingMe News Feed System
Building ZingMe News Feed System
 
Understanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And ProfitUnderstanding Memory Management In Spark For Fun And Profit
Understanding Memory Management In Spark For Fun And Profit
 
Introduction to Redis
Introduction to RedisIntroduction to Redis
Introduction to Redis
 
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GCHadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
Hadoop Meetup Jan 2019 - Dynamometer and a Case Study in NameNode GC
 
MongoDB WiredTiger Internals
MongoDB WiredTiger InternalsMongoDB WiredTiger Internals
MongoDB WiredTiger Internals
 
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation Buffers
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation BuffersHBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation Buffers
HBase HUG Presentation: Avoiding Full GCs with MemStore-Local Allocation Buffers
 
MongoDB Memory Management Demystified
MongoDB Memory Management DemystifiedMongoDB Memory Management Demystified
MongoDB Memory Management Demystified
 

Viewers also liked

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
 

Viewers also liked (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
 

Similar to 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
 

Similar to 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)
 

Recently uploaded

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
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
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 

Recently uploaded (20)

A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
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...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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?
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
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
 
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
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 

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