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

Post on 28-Nov-2014

1.512 views 1 download

description

 

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

1

OpenBlend LjubljanaSeptember 15th, 2011

Introduction to BytemanandThe Jokre

Sanne Grinovero

Software Engineer at Red Hat

Byteman

• It's a scriptable java agent

• Lets you change behavior at runtime– Without changing any sources– Simulating unexpected behaviour– Setting up specific scenarios

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?

Byteman can crash your disk

Byteman can cut your LAN cable

Byteman can generate an OutOfMemory exception right where you want it

Or it can do simple things too

Code deep dive: disk full

Proper error handling for IO exceptions are tested by: org.hibernate.search.test.errorhandling.ConcurrentMergeErrorHandledTest

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

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

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

Byteman built-in methodsTracing

• traceOpen, traceClose, traceln, traceStack, ...

Managing Shared Rule State• flag, clear, countDown, incrementCounter,

Timing• createTimer, getElapsedTime, resetTimer,

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);

Timing issues

• org.hibernate.search.test.query.timeout.JPATimeoutTest– Verifies a timeout is thrown if the query is

too slow

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

The Jokre

• https://github.com/infinispan/jokre

• A proof of concept of an advanced optimization technique

• Requires some knowledge of Infinispan

Infinispan API:mandates a return value

map.put( “user-34”, userInstance );

V put(K key, V value);

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

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!” );

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!

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

Jokr demo

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.

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.

Questions?Project Page http://www.jboss.org/byteman– downloads– documentation– user & developer forums– code repository

https://github.com/bytemanprojecthttps://github.com/infinispan