Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)

1,594 views

Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Byteman and The Jokre, Sanne Grinovero (JBoss by RedHat)

  1. 1. OpenBlend LjubljanaSeptember 15th, 2011 Introduction to Byteman and The Jokre Sanne Grinovero Software Engineer at Red Hat 1
  2. 2. Byteman• Its a scriptable java agent• Lets you change behavior at runtime – Without changing any sources – Simulating unexpected behaviour – Setting up specific scenarios
  3. 3. 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?
  4. 4. Byteman can crash your disk
  5. 5. Byteman can cut your LAN cable
  6. 6. Byteman can generate an OutOfMemory exception right where you want it
  7. 7. Or it can do simple things too
  8. 8. Code deep dive: disk fullProper error handling for IO exceptions aretested by:org.hibernate.search.test.errorhandling.ConcurrentMergeErrorHandledTest
  9. 9. 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
  10. 10. 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
  11. 11. 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
  12. 12. Byteman built-in methodsTracing• traceOpen, traceClose, traceln, traceStack, ...Managing Shared Rule State• flag, clear, countDown, incrementCounter,Timing• createTimer, getElapsedTime, resetTimer,
  13. 13. Helper ClassesBuilt-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);
  14. 14. Timing issues• org.hibernate.search.test.query.timeout. JPATimeoutTest – Verifies a timeout is thrown if the query is too slow
  15. 15. 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 JDKs /lib/tools.jar on classpath• See website and our projects for details
  16. 16. The Jokre• https://github.com/infinispan/jokre• A proof of concept of an advanced optimization technique• Requires some knowledge of Infinispan
  17. 17. Infinispan API: mandates a return valuemap.put( “user-34”, userInstance );V put(K key, V value);
  18. 18. A return value forces an RPCAssuming a DIST_ASYNC Infinispan cache:map.put( “k-1”, userInstance );1) ask the node storing “k-1” what thecurrent value is2) return that.. to nobody3) eventually perform the putasynchronously
  19. 19. 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!” );
  20. 20. 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, thats not the Map API anymore!
  21. 21. 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: lets see some magic in action
  22. 22. Jokr demo
  23. 23. 2011-09-15 10:43:15,794 WARN [Skynet] (main) JKR-00012 Problem XYZ detectedwithin your code. No worries, we just fixed it for you.
  24. 24. Just use Map, we fix it• This is a new concept: an “illegal” optimization is performed.• Its a proof of concept – feel free to suggest more use cases.
  25. 25. Questions?Project Page http://www.jboss.org/byteman– downloads– documentation– user & developer forums– code repositoryhttps://github.com/bytemanprojecthttps://github.com/infinispan

×