Skip to content

Plugin to The Matrix for (Virtual) Machines – Simulated Threads & Stacks

jinspired.logo.matrixLast week I was reminded of a quote from The Matrix (1999) film during a presentation on JXInsight/Simz to an industry analyst. Whilst the analyst could grasp the concepts of near real-time discrete event simulation engine he was having trouble understanding what exactly those events would be and how they’d manifest themselves in a single runtime that condensed and converged time and space across multiple application runtimes. How real would it really appear and how near to real-time?

Morpheus: Unfortunately, no one can be told what the Matrix is. You have to see it for yourself.

So this weekend gone I decided to tackle the presentation issues head-on. I would create a plugin that visualized what exactly our metering technology is observing and then show how this plugin would operate pretty much identical across actual application runtimes and a single runtime that simulated many application runtimes. I would do this in style, “matrix style” be it.

Take the red pill by clicking on the image below to play the screen recording. An even more exciting screen recording awaits you at the end of this post.

Note: More information on the distributed demo Akka application used in the screen recording can be found here.

What you have just seen is a Probes Open API plugin that samples the probe stack for all threads currently being metered within an application runtime. Each thread is represented as a column and each stack frame is a row with the stack rendering reverse (caller proceeds callee). Threads are grouped by the value of named variable, jxinsight.server.uuid, accessible through the Environment interface associated with a thread specific Context.


Most of the code for this metering plugin, which was less than 500 lines, is related to terminal printing. The actual Probes Open API usage is minimal. Here is how the matrix metering plugin collects the list of thread Context instances at the start of each frame paint (io) cycle.

Note: This code does not call out to the connected application runtimes as metering events are pushed and replayed in realtime within the simulated runtime. The contexts, and associated threads, iterated below exist in the simulated runtime much the same way they are present in the actual application runtime.


With the thread specific Context we can obtain the Stack.


Now with a thread Stack in hand we can navigate upwards from callee to caller using the getStack() method on each loop iteration.


To obtain the name of the probe, which in our case is a method name (including class namespace) we simply call getName().

Note: Probes have a composite namespace. This name abstraction allows the metering engine to model metered activities beyond Java methods such as SQL, web URLs or any other contextual value accessible at the point of metered interaction. It is this capability that allows us to us the same underlying engine irrespective of language such as in Ruby support via our JRuby integration. 


The only code that is Simz aware, in the sense that it is possible for each Java thread within a runtime to have a different server UUID, is the callback method invoked on the Plugin for each thread Context created in the runtime.


Simz creates a Java thread within its runtime for each Java thread created in the connected application runtime. Each thread, actual or simulated, has an associated metering context. For every instrumented Java method invocation in the application runtime that same metering instrumentation execution is performed in the simulated environment – in near realtime.


A Probes Open API plugin can be deployed into an actual real application runtime or a simulated application runtime and never know the difference. This is because from the perspective of activity metering there is no distinguishable difference, other than in a simulated environment there can be thousand of threads that are near real-time behavioral clones of their counterparts in multiple application runtimes. Want to see both cases in action? Click the image below.

Morpheus: Have you ever had a dream, Neo, that you were so sure was real? What if you were unable to wake from that dream? How would you know the difference between the dream world and the real world?


The Complexity and Challenges of IT Management within the Cloud
Time, Space & Data in Application Performance Monitoring