byteman and the jokre, sanne grinovero (jboss by redhat)

25
1 OpenBlend Ljubljana September 15th, 2011 Introduction to Byteman and The Jokre Sanne Grinovero Software Engineer at Red Hat

Upload: openblend-society

Post on 28-Nov-2014

1.514 views

Category:

Technology


1 download

DESCRIPTION

 

TRANSCRIPT

Page 1: 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

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

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)

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)

Byteman can crash your disk

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

Byteman can cut your LAN cable

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

Byteman can generate an OutOfMemory exception right where you want it

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

Or it can do simple things too

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

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

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)

Jokr demo

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

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)

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)

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

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