Mais conteúdo relacionado Semelhante a Runtime compilation and code execution in groovy (20) Mais de Vitebsk Miniq (20) Runtime compilation and code execution in groovy2. © 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
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
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
21. © 2020 EPAM Systems, Inc.
Constant class loading?
Jmeter: 50 requests per second, 300 seconds
CATALINA_OPTS=-XX:MaxMetaspaceSize=100m
23. © 2020 EPAM Systems, Inc.
Constant class loading issue
23
24. © 2020 EPAM Systems, Inc.
Constant class loading issue
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