SlideShare une entreprise Scribd logo
1  sur  38
Télécharger pour lire hors ligne
Runtime compilation and
code execution in groovy
© 2020 EPAM Systems, Inc.
S o f t w a r e E n g i n e e r a t E P A M
R a m a n M a s k a l e n k a
© 2020 EPAM Systems, Inc.
Disclaimer
© 2020 EPAM Systems, Inc.
Problem statement
© 2020 EPAM Systems, Inc.
Problem statement
© 2020 EPAM Systems, Inc.
When can we use it
A S A P R OX Y S E R V I C E W I T H T R A N S F O R M E R
© 2020 EPAM Systems, Inc.
When can we use it
A S A C O M P L E X DY N A M I C A L LY C A LC U L AT E D C O N F I G U R AT I O N
© 2020 EPAM Systems, Inc.
How can we solve it?
© 2020 EPAM Systems, Inc.
AWS Step Function
© 2020 EPAM Systems, Inc.
AWS Step Function
Pros
• AWS is popular
• Different languages support
• Version control
• Source editor
• Lambdas be integrated with Amazon
Xray for tracing
Cons
• Lambdas can be costly if we have a
lot of scripts and high request load
• Appeared only in 2018
© 2020 EPAM Systems, Inc.
How can we solve it?
JSR 199 (mvn-classloadr, jianimo)
Write your own compiler
JSR 223
Oracle Nashorn engine (Till Java 11)
JSR 223
ScriptEngineManager().getEngineByExt
ension("kts")
© 2020 EPAM Systems, Inc.
How can we solve it?
GroovyClassLoader
© 2020 EPAM Systems, Inc.
How does it work?
H I G H L E V E L F LO W
© 2020 EPAM Systems, Inc.
How does it work?
S I M P L EST C O D E E X A M P L E
© 2020 EPAM Systems, Inc.
How does it work?
S I M P L EST C O D E E X A M P L E
© 2020 EPAM Systems, Inc.
How does it work?
DY N A M I C S C R I P T P R O P E R T I ES
• Script state clears between runs (For example script “def v; v = v ? v+1 : 1” will
return the same result during multiple executions)
• Binding variables are mutable and can be used to store/pass state (For example if
we have binding variable “v” and script “v = v+1” binding will be changed during
execution)
• Binding doesn’t create a copy of the passed map so it will be changed aswell
• Script code behaves the same as any other groovy code – you can use “import”
statements in it
• GroovyClassLoader will use your current thread class loader as parent by default,
but you can provide desired parent on your own
© 2020 EPAM Systems, Inc.
Errors and stack trace
D E FAU LT
© 2020 EPAM Systems, Inc.
Errors and stack trace
SA N I T I Z E D A P P R O AC H
© 2020 EPAM Systems, Inc.
Servlet example
© 2020 EPAM Systems, Inc.
© 2020 EPAM Systems, Inc.
Constant class loading?
Jmeter: 50 requests per second, 300 seconds
CATALINA_OPTS=-XX:MaxMetaspaceSize=100m
© 2020 EPAM Systems, Inc.
© 2020 EPAM Systems, Inc.
Constant class loading issue
23
© 2020 EPAM Systems, Inc.
Constant class loading issue
© 2020 EPAM Systems, Inc.
© 2020 EPAM Systems, Inc.
Performance
26
Software
• Jmeter script
• 50 requests per second
• Spf4j to record execution
• Win 10 x64
• Java 8 (1.8.0_151)
• Tomcat 8.5.24
Hardware
• Intel core i5-8600k
• 16 Gb OZU
© 2020 EPAM Systems, Inc.
Performance Jmeter request
27
© 2020 EPAM Systems, Inc.
Performance step 1 parse class max
28
© 2020 EPAM Systems, Inc.
Performance step 1 parse class avg min
29
© 2020 EPAM Systems, Inc.
Performance step 2 create script
30
© 2020 EPAM Systems, Inc.
Performance step 3 run script max
31
© 2020 EPAM Systems, Inc.
Performance step 3 run script avg-min
32
© 2020 EPAM Systems, Inc.
Performance cleanup classes max
33
© 2020 EPAM Systems, Inc.
Performance cleanup classes avg-min
34
© 2020 EPAM Systems, Inc.
Performance jmeter endpoint summary
35
Label # Samples
Avera
ge
Media
n
90%
Line
95%
Line
99%
Line Min Max Error %
Throughp
ut
Receiv
ed
KB/se
c
Sent
KB/se
c
RandomScript 29955 28 17 36 45 99 10 30790,000% 49.92/s8,40 81,86
© 2020 EPAM Systems, Inc.
Pros and cons
Pros
• Reconfiguration on flight
• Works great as transaction
transformer
• Interactive development in runtime
• Almost zero time for deployment
Cons
• Reinventing Source control
• Hard to review
• High Security risks
• Self implemented testing
• Harder to monitor
• High risks of get fired in case of
production error caused by your
change
• More often Major GC
36
© 2020 EPAM Systems, Inc.
CONFIDENTIAL | © 2019 EPAM Systems, Inc.

Contenu connexe

Similaire à Runtime compilation and code execution in groovy

RMiller.FromMaxL.presentation
RMiller.FromMaxL.presentationRMiller.FromMaxL.presentation
RMiller.FromMaxL.presentation
Randy Miller
 
How to Determine if You Are Well-Architected for Reliability
How to Determine if You Are Well-Architected for ReliabilityHow to Determine if You Are Well-Architected for Reliability
How to Determine if You Are Well-Architected for Reliability
Amazon Web Services
 

Similaire à Runtime compilation and code execution in groovy (20)

RMiller.FromMaxL.presentation
RMiller.FromMaxL.presentationRMiller.FromMaxL.presentation
RMiller.FromMaxL.presentation
 
MuleSoft Sizing Guidelines - VirtualMuleys
MuleSoft Sizing Guidelines - VirtualMuleysMuleSoft Sizing Guidelines - VirtualMuleys
MuleSoft Sizing Guidelines - VirtualMuleys
 
Jump-start your application migration to AWS with CloudEndure - STG305 - New ...
Jump-start your application migration to AWS with CloudEndure - STG305 - New ...Jump-start your application migration to AWS with CloudEndure - STG305 - New ...
Jump-start your application migration to AWS with CloudEndure - STG305 - New ...
 
Castles in the Cloud: Developing with Google App Engine
Castles in the Cloud: Developing with Google App EngineCastles in the Cloud: Developing with Google App Engine
Castles in the Cloud: Developing with Google App Engine
 
Can they really do that: CloudFormation, SAM and CDK tips'n'tricks
Can they really do that: CloudFormation, SAM and CDK tips'n'tricksCan they really do that: CloudFormation, SAM and CDK tips'n'tricks
Can they really do that: CloudFormation, SAM and CDK tips'n'tricks
 
How to Determine if You Are Well-Architected for Reliability
How to Determine if You Are Well-Architected for ReliabilityHow to Determine if You Are Well-Architected for Reliability
How to Determine if You Are Well-Architected for Reliability
 
AWS Startup Day Kyiv: Container services on AWS. Comparing Amazon ECS, AWS Fa...
AWS Startup Day Kyiv: Container services on AWS. Comparing Amazon ECS, AWS Fa...AWS Startup Day Kyiv: Container services on AWS. Comparing Amazon ECS, AWS Fa...
AWS Startup Day Kyiv: Container services on AWS. Comparing Amazon ECS, AWS Fa...
 
AWS Container services
AWS Container servicesAWS Container services
AWS Container services
 
Deep Dive into AWS Fargate - CON333 - re:Invent 2017
Deep Dive into AWS Fargate - CON333 - re:Invent 2017Deep Dive into AWS Fargate - CON333 - re:Invent 2017
Deep Dive into AWS Fargate - CON333 - re:Invent 2017
 
JNUC 2017: Open Distribution Server
JNUC 2017: Open Distribution ServerJNUC 2017: Open Distribution Server
JNUC 2017: Open Distribution Server
 
EMC World 2016 - mioaITL.08 Infrastructure as Code: Not Your Parent's Data Ce...
EMC World 2016 - mioaITL.08 Infrastructure as Code: Not Your Parent's Data Ce...EMC World 2016 - mioaITL.08 Infrastructure as Code: Not Your Parent's Data Ce...
EMC World 2016 - mioaITL.08 Infrastructure as Code: Not Your Parent's Data Ce...
 
Rodney Lester: Well-Architected - Reliability Instructor Led Lab.pdf
Rodney Lester: Well-Architected - Reliability Instructor Led Lab.pdfRodney Lester: Well-Architected - Reliability Instructor Led Lab.pdf
Rodney Lester: Well-Architected - Reliability Instructor Led Lab.pdf
 
Salt conf 2014 - Using SaltStack in high availability environments
Salt conf 2014 - Using SaltStack in high availability environmentsSalt conf 2014 - Using SaltStack in high availability environments
Salt conf 2014 - Using SaltStack in high availability environments
 
FDM to FDMEE migration utility
FDM to FDMEE migration utilityFDM to FDMEE migration utility
FDM to FDMEE migration utility
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
QCon Shanghai: Trends in Application Development
QCon Shanghai: Trends in Application DevelopmentQCon Shanghai: Trends in Application Development
QCon Shanghai: Trends in Application Development
 
GAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECSGAM307_Ubisoft How For Honor Runs Using Amazon ECS
GAM307_Ubisoft How For Honor Runs Using Amazon ECS
 
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
Remove Undifferentiated Heavy Lifting from Jenkins (DEV201-R1) - AWS re:Inven...
 
Advanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step FunctionsAdvanced Serverless Apps With Step Functions
Advanced Serverless Apps With Step Functions
 
WebAssembly & Zero Trust for Code
WebAssembly & Zero Trust for CodeWebAssembly & Zero Trust for Code
WebAssembly & Zero Trust for Code
 

Plus de Vitebsk Miniq

The 5 Laws of Software Estimates
The 5 Laws of Software EstimatesThe 5 Laws of Software Estimates
The 5 Laws of Software Estimates
Vitebsk Miniq
 

Plus de Vitebsk Miniq (20)

The 5 Laws of Software Estimates
The 5 Laws of Software EstimatesThe 5 Laws of Software Estimates
The 5 Laws of Software Estimates
 
Latest & Greatest Observability Release 7.9
Latest & Greatest Observability Release 7.9Latest & Greatest Observability Release 7.9
Latest & Greatest Observability Release 7.9
 
Тестирование Spring-based приложений
Тестирование Spring-based приложенийТестирование Spring-based приложений
Тестирование Spring-based приложений
 
Семантический поиск - что это, как работает и чем отличается от просто поиска
Семантический поиск - что это, как работает и чем отличается от просто поискаСемантический поиск - что это, как работает и чем отличается от просто поиска
Семантический поиск - что это, как работает и чем отличается от просто поиска
 
Локализационное тестирование - это не только перевод
Локализационное тестирование - это не только переводЛокализационное тестирование - это не только перевод
Локализационное тестирование - это не только перевод
 
ISTQB Сертификация тестировщиков: быть или не быть?
ISTQB Сертификация тестировщиков: быть или не быть?ISTQB Сертификация тестировщиков: быть или не быть?
ISTQB Сертификация тестировщиков: быть или не быть?
 
Apollo GraphQL Federation
Apollo GraphQL FederationApollo GraphQL Federation
Apollo GraphQL Federation
 
Who is a functional tester
Who is a functional testerWho is a functional tester
Who is a functional tester
 
Crawling healthy
Crawling healthyCrawling healthy
Crawling healthy
 
Вперед в прошлое
Вперед в прошлоеВперед в прошлое
Вперед в прошлое
 
CloudFormation experience
CloudFormation experienceCloudFormation experience
CloudFormation experience
 
Learning Intelligence: the story of mine
Learning Intelligence: the story of mineLearning Intelligence: the story of mine
Learning Intelligence: the story of mine
 
Как программисты могут спасти мир
Как программисты могут спасти мирКак программисты могут спасти мир
Как программисты могут спасти мир
 
Использование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложенийИспользование AzureDevOps при разработке микросервисных приложений
Использование AzureDevOps при разработке микросервисных приложений
 
Distributed tracing system in action. Instana Tracing.
Distributed tracing system in action. Instana Tracing.Distributed tracing system in action. Instana Tracing.
Distributed tracing system in action. Instana Tracing.
 
Насорил - убери!
Насорил - убери!Насорил - убери!
Насорил - убери!
 
Styled-components. Что? Когда? И зачем?
Styled-components. Что? Когда? И зачем?Styled-components. Что? Когда? И зачем?
Styled-components. Что? Когда? И зачем?
 
Красные флаги и розовые очки
Красные флаги и розовые очкиКрасные флаги и розовые очки
Красные флаги и розовые очки
 
CSS. Практика
CSS. ПрактикаCSS. Практика
CSS. Практика
 
Разделяй и властвуй!
Разделяй и властвуй!Разделяй и властвуй!
Разделяй и властвуй!
 

Dernier

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 

Dernier (20)

Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
THE BEST IPTV in GERMANY for 2024: IPTVreel
THE BEST IPTV in  GERMANY for 2024: IPTVreelTHE BEST IPTV in  GERMANY for 2024: IPTVreel
THE BEST IPTV in GERMANY for 2024: IPTVreel
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
The UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, OcadoThe UX of Automation by AJ King, Senior UX Researcher, Ocado
The UX of Automation by AJ King, Senior UX Researcher, Ocado
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Agentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdfAgentic RAG What it is its types applications and implementation.pdf
Agentic RAG What it is its types applications and implementation.pdf
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 

Runtime compilation and code execution in groovy

  • 1. Runtime compilation and code execution in groovy
  • 2. © 2020 EPAM Systems, Inc. S o f t w a r e E n g i n e e r a t E P A M R a m a n M a s k a l e n k a
  • 3. © 2020 EPAM Systems, Inc. Disclaimer
  • 4. © 2020 EPAM Systems, Inc. Problem statement
  • 5. © 2020 EPAM Systems, Inc. Problem statement
  • 6. © 2020 EPAM Systems, Inc. When can we use it A S A P R OX Y S E R V I C E W I T H T R A N S F O R M E R
  • 7. © 2020 EPAM Systems, Inc. When can we use it A S A C O M P L E X DY N A M I C A L LY C A LC U L AT E D C O N F I G U R AT I O N
  • 8. © 2020 EPAM Systems, Inc. How can we solve it?
  • 9. © 2020 EPAM Systems, Inc. AWS Step Function
  • 10. © 2020 EPAM Systems, Inc. AWS Step Function Pros • AWS is popular • Different languages support • Version control • Source editor • Lambdas be integrated with Amazon Xray for tracing Cons • Lambdas can be costly if we have a lot of scripts and high request load • Appeared only in 2018
  • 11. © 2020 EPAM Systems, Inc. How can we solve it? JSR 199 (mvn-classloadr, jianimo) Write your own compiler JSR 223 Oracle Nashorn engine (Till Java 11) JSR 223 ScriptEngineManager().getEngineByExt ension("kts")
  • 12. © 2020 EPAM Systems, Inc. How can we solve it? GroovyClassLoader
  • 13. © 2020 EPAM Systems, Inc. How does it work? H I G H L E V E L F LO W
  • 14. © 2020 EPAM Systems, Inc. How does it work? S I M P L EST C O D E E X A M P L E
  • 15. © 2020 EPAM Systems, Inc. How does it work? S I M P L EST C O D E E X A M P L E
  • 16. © 2020 EPAM Systems, Inc. How does it work? DY N A M I C S C R I P T P R O P E R T I ES • Script state clears between runs (For example script “def v; v = v ? v+1 : 1” will return the same result during multiple executions) • Binding variables are mutable and can be used to store/pass state (For example if we have binding variable “v” and script “v = v+1” binding will be changed during execution) • Binding doesn’t create a copy of the passed map so it will be changed aswell • Script code behaves the same as any other groovy code – you can use “import” statements in it • GroovyClassLoader will use your current thread class loader as parent by default, but you can provide desired parent on your own
  • 17. © 2020 EPAM Systems, Inc. Errors and stack trace D E FAU LT
  • 18. © 2020 EPAM Systems, Inc. Errors and stack trace SA N I T I Z E D A P P R O AC H
  • 19. © 2020 EPAM Systems, Inc. Servlet example
  • 20. © 2020 EPAM Systems, Inc.
  • 21. © 2020 EPAM Systems, Inc. Constant class loading? Jmeter: 50 requests per second, 300 seconds CATALINA_OPTS=-XX:MaxMetaspaceSize=100m
  • 22. © 2020 EPAM Systems, Inc.
  • 23. © 2020 EPAM Systems, Inc. Constant class loading issue 23
  • 24. © 2020 EPAM Systems, Inc. Constant class loading issue
  • 25. © 2020 EPAM Systems, Inc.
  • 26. © 2020 EPAM Systems, Inc. Performance 26 Software • Jmeter script • 50 requests per second • Spf4j to record execution • Win 10 x64 • Java 8 (1.8.0_151) • Tomcat 8.5.24 Hardware • Intel core i5-8600k • 16 Gb OZU
  • 27. © 2020 EPAM Systems, Inc. Performance Jmeter request 27
  • 28. © 2020 EPAM Systems, Inc. Performance step 1 parse class max 28
  • 29. © 2020 EPAM Systems, Inc. Performance step 1 parse class avg min 29
  • 30. © 2020 EPAM Systems, Inc. Performance step 2 create script 30
  • 31. © 2020 EPAM Systems, Inc. Performance step 3 run script max 31
  • 32. © 2020 EPAM Systems, Inc. Performance step 3 run script avg-min 32
  • 33. © 2020 EPAM Systems, Inc. Performance cleanup classes max 33
  • 34. © 2020 EPAM Systems, Inc. Performance cleanup classes avg-min 34
  • 35. © 2020 EPAM Systems, Inc. Performance jmeter endpoint summary 35 Label # Samples Avera ge Media n 90% Line 95% Line 99% Line Min Max Error % Throughp ut Receiv ed KB/se c Sent KB/se c RandomScript 29955 28 17 36 45 99 10 30790,000% 49.92/s8,40 81,86
  • 36. © 2020 EPAM Systems, Inc. Pros and cons Pros • Reconfiguration on flight • Works great as transaction transformer • Interactive development in runtime • Almost zero time for deployment Cons • Reinventing Source control • Hard to review • High Security risks • Self implemented testing • Harder to monitor • High risks of get fired in case of production error caused by your change • More often Major GC 36
  • 37. © 2020 EPAM Systems, Inc.
  • 38. CONFIDENTIAL | © 2019 EPAM Systems, Inc.