Java Code Examples for cern.jet.random.Normal#nextInt()

The following examples show how to use cern.jet.random.Normal#nextInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TimerSample.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    Timer timer = Timer.builder("timer")
            .publishPercentileHistogram()
            .publishPercentiles(0.5, 0.95, 0.99)
            .serviceLevelObjectives(Duration.ofMillis(275), Duration.ofMillis(300), Duration.ofMillis(500))
            .distributionStatisticExpiry(Duration.ofSeconds(10))
            .distributionStatisticBufferLength(3)
            .register(registry);

    AtomicLong totalCount = new AtomicLong();
    AtomicLong totalTime = new AtomicLong();
    FunctionTimer.builder("ftimer", totalCount, t -> totalCount.get(), t -> totalTime.get(), TimeUnit.MILLISECONDS)
            .register(registry);

    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(250, 50, r);

    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1))
            .doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
            .subscribe();

    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10))
            .doOnEach(d -> {
                if (incomingRequests.nextDouble() + 0.4 > 0) {
                    // pretend the request took some amount of time, such that the time is
                    // distributed normally with a mean of 250ms
                    int latency = latencyForThisSecond.get();
                    timer.record(latency, TimeUnit.MILLISECONDS);
                    totalTime.addAndGet(latency);
                    totalCount.incrementAndGet();
                }
            })
            .blockLast();
}
 
Example 2
Source File: LongTaskTimerSample.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();
    LongTaskTimer timer = registry.more().longTaskTimer("longTaskTimer");

    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(30, 50, r);

    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1))
            .doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
            .subscribe();

    final Map<LongTaskTimer.Sample, CountDownLatch> tasks = new ConcurrentHashMap<>();

    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofSeconds(1))
            .doOnEach(d -> {
                if (incomingRequests.nextDouble() + 0.4 > 0 && tasks.isEmpty()) {
                    int taskDur;
                    while ((taskDur = duration.nextInt()) < 0);
                    synchronized (tasks) {
                        tasks.put(timer.start(), new CountDownLatch(taskDur));
                    }
                }

                synchronized (tasks) {
                    for (Map.Entry<LongTaskTimer.Sample, CountDownLatch> e : tasks.entrySet()) {
                        e.getValue().countDown();
                        if (e.getValue().getCount() == 0) {
                            e.getKey().stop();
                            tasks.remove(e.getKey());
                        }
                    }
                }
            })
            .blockLast();
}
 
Example 3
Source File: TimerMaximumThroughputSample.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
        MeterRegistry registry = SampleConfig.myMonitoringSystem();
        Timer timer = Timer.builder("timer")
                .publishPercentileHistogram()
//                .publishPercentiles(0.5, 0.95, 0.99)
                .serviceLevelObjectives(Duration.ofMillis(275), Duration.ofMillis(300), Duration.ofMillis(500))
                .distributionStatisticExpiry(Duration.ofSeconds(10))
                .distributionStatisticBufferLength(3)
                .register(registry);

        RandomEngine r = new MersenneTwister64(0);
        Normal duration = new Normal(250, 50, r);

        AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
        Flux.interval(Duration.ofSeconds(1))
                .doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
                .subscribe();

        Stream<Integer> infiniteStream = Stream.iterate(0, i -> (i + 1) % 1000);
        Flux.fromStream(infiniteStream)
                .parallel(4)
                .runOn(Schedulers.parallel())
                .doOnEach(d -> timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS))
                .subscribe();

        Flux.never().blockLast();
    }
 
Example 4
Source File: FunctionTimerSample.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();

    Timer timer = Timer.builder("timer")
        .publishPercentiles(0.5, 0.95)
        .register(registry);

    Object placeholder = new Object();
    AtomicLong totalTimeNanos = new AtomicLong(0);
    AtomicLong totalCount = new AtomicLong(0);

    FunctionTimer.builder("ftimer", placeholder, p -> totalCount.get(), p -> totalTimeNanos.get(), TimeUnit.NANOSECONDS)
        .register(registry);

    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal duration = new Normal(250, 50, r);

    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1))
        .doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
        .subscribe();

    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10))
        .doOnEach(d -> {
            if (incomingRequests.nextDouble() + 0.4 > 0) {
                // pretend the request took some amount of time, such that the time is
                // distributed normally with a mean of 250ms
                timer.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
                totalCount.incrementAndGet();
                totalTimeNanos.addAndGet((long) TimeUtils.millisToUnit(latencyForThisSecond.get(), TimeUnit.NANOSECONDS));
            }
        })
        .blockLast();
}
 
Example 5
Source File: SimulatedEndpointInstrumentation.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
    MeterRegistry registry = SampleConfig.myMonitoringSystem();

    Timer e1Success = Timer.builder("http.server.requests")
        .tags("uri", "/api/bar")
        .tags("response", "200")
        .publishPercentiles(0.5, 0.95)
        .register(registry);

    Timer e2Success = Timer.builder("http.server.requests")
        .tags("uri", "/api/foo")
        .tags("response", "200")
        .publishPercentiles(0.5, 0.95)
        .register(registry);

    Timer e1Fail = Timer.builder("http.server.requests")
        .tags("uri", "/api/bar")
        .tags("response", "500")
        .publishPercentiles(0.5, 0.95)
        .register(registry);

    Timer e2Fail = Timer.builder("http.server.requests")
        .tags("uri", "/api/foo")
        .tags("response", "500")
        .publishPercentiles(0.5, 0.95)
        .register(registry);

    RandomEngine r = new MersenneTwister64(0);
    Normal incomingRequests = new Normal(0, 1, r);
    Normal successOrFail = new Normal(0, 1, r);

    Normal duration = new Normal(250, 50, r);
    Normal duration2 = new Normal(250, 50, r);

    AtomicInteger latencyForThisSecond = new AtomicInteger(duration.nextInt());
    Flux.interval(Duration.ofSeconds(1))
        .doOnEach(d -> latencyForThisSecond.set(duration.nextInt()))
        .subscribe();

    AtomicInteger latencyForThisSecond2 = new AtomicInteger(duration2.nextInt());
    Flux.interval(Duration.ofSeconds(1))
        .doOnEach(d -> latencyForThisSecond2.set(duration2.nextInt()))
        .subscribe();

    // the potential for an "incoming request" every 10 ms
    Flux.interval(Duration.ofMillis(10))
        .doOnEach(d -> {
            // are we going to receive a request for /api/foo?
            if (incomingRequests.nextDouble() + 0.4 > 0) {
                if (successOrFail.nextDouble() + 0.8 > 0) {
                    // pretend the request took some amount of time, such that the time is
                    // distributed normally with a mean of 250ms
                    e1Success.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
                }
                else {
                    e1Fail.record(latencyForThisSecond.get(), TimeUnit.MILLISECONDS);
                }
            }
        })
        .subscribe();

    // the potential for an "incoming request" every 1 ms
    Flux.interval(Duration.ofMillis(1))
        .doOnEach(d -> {
            // are we going to receive a request for /api/bar?
            if (incomingRequests.nextDouble() + 0.4 > 0) {
                if (successOrFail.nextDouble() + 0.8 > 0) {
                    // pretend the request took some amount of time, such that the time is
                    // distributed normally with a mean of 250ms
                    e2Success.record(latencyForThisSecond2.get(), TimeUnit.MILLISECONDS);
                }
                else {
                    e2Fail.record(latencyForThisSecond2.get(), TimeUnit.MILLISECONDS);
                }
            }
        })
        .blockLast();
}