byteman and the jokre, sanne grinovero (jboss by redhat)
DESCRIPTION
TRANSCRIPT
![Page 1: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/1.jpg)
1
OpenBlend LjubljanaSeptember 15th, 2011
Introduction to BytemanandThe Jokre
Sanne Grinovero
Software Engineer at Red Hat
![Page 2: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/2.jpg)
Byteman
• It's a scriptable java agent
• Lets you change behavior at runtime– Without changing any sources– Simulating unexpected behaviour– Setting up specific scenarios
![Page 3: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/3.jpg)
How are you going to test for...
• How is your flush operation going to behave when the disk crashes ?
• Is your code good enough to not corrupt in-flight processed data when an OOM excepion happens?
• What if the TCP connection is terminated during that?
![Page 4: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/4.jpg)
Byteman can crash your disk
![Page 5: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/5.jpg)
Byteman can cut your LAN cable
![Page 6: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/6.jpg)
Byteman can generate an OutOfMemory exception right where you want it
![Page 7: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/7.jpg)
Or it can do simple things too
![Page 8: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/8.jpg)
Code deep dive: disk full
Proper error handling for IO exceptions are tested by: org.hibernate.search.test.errorhandling.ConcurrentMergeErrorHandledTest
![Page 9: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/9.jpg)
Event-driven scripts
• You can avoid mocks, conditional builds, and have the code change when chosen conditions trigger.– Cleaner code
• Can attach dynamically after the running code was written– Used for “debug” and hot-patching of
running production applications
![Page 10: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/10.jpg)
Byte(code) man(ipulation)
Available right now in a JVM near you
– transform code/class structure at load
– retransform code only after load
– java.lang.instrument
![Page 11: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/11.jpg)
Byte(code) man(ipulation)
• Byteman makes it easy– inject Java code direct into Java code
• Byteman makes it cheap– low transformation cost– tightly scoped changes
• Byteman produces reversible changes– no structural changes
![Page 12: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/12.jpg)
Byteman built-in methodsTracing
• traceOpen, traceClose, traceln, traceStack, ...
Managing Shared Rule State• flag, clear, countDown, incrementCounter,
Timing• createTimer, getElapsedTime, resetTimer,
![Page 13: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/13.jpg)
Helper Classes
Built-ins are POJO public methods
• take a look org.jboss.byteman.rule.Helper
• You can use any POJO you likeclass DBHelper {
public void trace(String msg, Record rec);
![Page 14: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/14.jpg)
Timing issues
• org.hibernate.search.test.query.timeout.JPATimeoutTest– Verifies a timeout is thrown if the query is
too slow
![Page 15: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/15.jpg)
How to enable it
• As an explicit agent-javaagent:/path/to/agent.jar=agentoptions
Auto-loading the agent– As with the BMunit examples
– Works with JUnit and TestNG– Requires the JDK's /lib/tools.jar on
classpath
• See website and our projects for details
![Page 16: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/16.jpg)
The Jokre
• https://github.com/infinispan/jokre
• A proof of concept of an advanced optimization technique
• Requires some knowledge of Infinispan
![Page 17: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/17.jpg)
Infinispan API:mandates a return value
map.put( “user-34”, userInstance );
V put(K key, V value);
![Page 18: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/18.jpg)
A return value forces an RPC
Assuming a DIST_ASYNC Infinispan cache:
map.put( “k-1”, userInstance );
1) ask the node storing “k-1” what the current value is
2) return that.. to nobody
3) eventually perform the put asynchronously
![Page 19: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/19.jpg)
A return value forces an RPC
• So even async caches often perform as sync caches, unless flags are used:
cache.withFlags(
Flag.SKIP_REMOTE_LOOKUP,
Flag.SKIP_CACHE_LOAD
).put( “k-1”, “hi!” );
![Page 20: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/20.jpg)
A return value forces an RPC
• So even async caches often perform as sync caches, unless flags are used:
cache.withFlags(
Flag.SKIP_REMOTE_LOOKUP,
Flag.SKIP_CACHE_LOAD
).put( “k-1”, “hi!” );
Hey, that's not the Map API anymore!
![Page 21: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/21.jpg)
Tradeoff: use proprietary or standard API?
• We all prefer well known APIs– JPA/Hibernate ?– Interface and standardization often lags
behind: there is a performance hit you pay.
• It seems in some cases you can have both: let's see some magic in action
![Page 22: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/22.jpg)
Jokr demo
![Page 23: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/23.jpg)
2011-09-15 10:43:15,794 WARN [Skynet] (main) JKR-00012 Problem XYZ detected within your code. No worries, we just fixed
it for you.
![Page 24: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/24.jpg)
Just use Map, we fix it
• This is a new concept: an “illegal” optimization is performed.
• It's a proof of concept– feel free to suggest more use cases.
![Page 25: Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)](https://reader034.vdocument.in/reader034/viewer/2022050919/547aad96b4af9fa5158b4b8b/html5/thumbnails/25.jpg)
Questions?Project Page http://www.jboss.org/byteman– downloads– documentation– user & developer forums– code repository
https://github.com/bytemanprojecthttps://github.com/infinispan