Coder Social home page Coder Social logo

jvm-alloc-rate-meter's Introduction

jvm-alloc-rate-meter

A trivial Java library for continuous monitoring of JVM heap allocation rate. Many GCs can report this metric in their logs, but it's hard to extract that in real time. This library solves that.

jvm-alloc-rate-meter starts a background thread that measures how heap usage changes between the specified intervals and reports the result into a callback. You get to choose where the data will go โ€” log it, send to a monitoring solution (Metrics, StatsD, etc.), or aggregate some other way.

Usage

First, add it to your dependencies:

Java

You are safe to use this library in any Java project, it doesn't explicitly depend on Clojure (or anything else). You can also forgo the dependency and just paste MeterThread class directly into your project.

import jvm_alloc_rate_meter.MeterThread;

// ...

MeterThread t = new MeterThread((r) -> System.out.println("Rate is: " + (r / 1e6) + " MB/sec"));
t.start();

// To stop the meter thread
t.terminate();

The first argument to MeterThread's constructor is a LongConsumer callback that will be called with every new measurement of allocation rate in bytes/sec.

The second (optional) argument is the measurement interval in milliseconds (1000 by default). Regardless of the interval length, the reported rate will be normalized to per-second value. Note that the callback might not be called on each interval, because under certain conditions we can't reliably measure the allocation rate (if both the garbage collection happened and a few of the heavy-allocating threads died).

Here's an example of combining jvm-alloc-rate-meter with Dropwizard Metrics:

import jvm_alloc_rate_meter.MeterThread;
import com.codahale.metrics.Histogram;
import com.codahale.metrics.SlidingTimeWindowArrayReservoir;
import java.util.concurrent.TimeUnit;

// ...

Histogram hist = new Histogram(new SlidingTimeWindowArrayReservoir(10, TimeUnit.SECONDS));
MeterThread mt = new MeterThread(hist::update);
mt.start();

// Now, you can forward this histogram to Graphite, or check the values manually, e.g.:
hist.getSnaphot.getMean();

Clojure

(require '[jvm-alloc-rate-meter.core :as ameter])
(def am (ameter/start-alloc-rate-meter #(println "Rate is:" (/ % 1e6) "MB/sec")))

;; Test it out
(while true
  (byte-array 1e7)
  (Thread/sleep 100))

;; The meter should report ~100 MB/sec allocation rate into the console.

;; To stop the meter thread
(am)

The only function start-alloc-rate-meter accepts an unary function as an argument and starts the measuring thread. See the section above using the library from Java for the details.

License

jvm-hiccup-meter is distributed under the Eclipse Public License. See LICENSE.

Copyright 2018-2024 Alexander Yakushev

jvm-alloc-rate-meter's People

Contributors

alexander-yakushev avatar gunnarmorling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

jvm-alloc-rate-meter's Issues

Question: alloc rate meter with heap monitoring

Hi, thanks for this interesting tool. I would like to try it out but I am wondering whether I am going to see any benefits of using it if I already have a heap monitoring in place and I am - kind of - able to see how it behaves.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.