Skip to content

Instantly share code, notes, and snippets.

View Kurukshetran's full-sized avatar
🎯
Focusing

Kurukshetran Kurukshetran

🎯
Focusing
View GitHub Profile

Motivation

Integrate JMH (Java Microbenchmarking Harness) with Spring (Boot) and make developing and running benchmarks as easy and convinent as writing tests.

Idea

Wrap the necessary JMH boilerplate code within JUnit to benefit from all the existing test infrastructure Spring (Boot) provides. It should be as easy and convinent to write benchmarks as it is to write tests.

TL;DR;

@Kurukshetran
Kurukshetran / HttpClientConfiguration.java
Created July 31, 2019 06:46 — forked from mikeapr4/HttpClientConfiguration.java
Java Spring Configuration to provide the Apache HttpClient as per recommendations from http://www.baeldung.com/httpclient-connection-management
import org.apache.http.HeaderElement;
import org.apache.http.HeaderElementIterator;
import org.apache.http.HttpResponse;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.config.Registry;
import org.apache.http.config.RegistryBuilder;
import org.apache.http.conn.ConnectionKeepAliveStrategy;
import org.apache.http.conn.socket.ConnectionSocketFactory;
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
@Kurukshetran
Kurukshetran / FileLockSimulator.java
Created July 19, 2019 11:05 — forked from stefanrufer/FileLockSimulator.java
FileLockSimulator: a small application for simulate the behavior of FileAppender in prudent mode
/**
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2011, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*

Thread Pools

Thread pools on the JVM should usually be divided into the following three categories:

  1. CPU-bound
  2. Blocking IO
  3. Non-blocking IO polling

Each of these categories has a different optimal configuration and usage pattern.

@Kurukshetran
Kurukshetran / gist:812736354f087e386b36112fe7b517a6
Created July 15, 2019 06:26 — forked from ravin-singh/gist:8654b654163c508cdb227a621fe078f0
Micrometer metrics exporter for apache http connection pool
1. Create a scheduler to add new routes
@Scheduled(fixedRate = 300000)
public void updateHttpRoutes() {
Set<HttpRoute> routes = poolingHttpClientConnectionManager.getRoutes();
for (HttpRoute route : routes) {
httpMetricsTracker.add(route, poolingHttpClientConnectionManager);
}
}
@Kurukshetran
Kurukshetran / ClientHttpPoolConfiguration.java
Created July 11, 2019 06:25 — forked from soverby/ClientHttpPoolConfiguration.java
RestTemplate backed by Apache HttpClient Connection Pool. Addresses RestTemplate HttpConnection exhaustion. Note this implementation is not route tunable and should be expanded when tuning by route is required. Example error: I/O error on POST request for "https://someendpoint": Timeout waiting for connection from pool; nested exception is org.a…
import org.apache.http.client.config.RequestConfig;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ClientHttpPoolConfiguration {
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ApacheLogParser {
@Kurukshetran
Kurukshetran / gist:3b864e63d943ff482ccf11cc9019142e
Created April 22, 2019 10:55 — forked from mwinters0/gist:c70d195c5c5670d1625f
Shell one-liner to parse apache access logs and extract a unique URL list with hit count, querystring excluded.
cat access.log | awk -F\" '{print $2}' | awk '{print $2}' | sed '/^$/d' | sed 's/\?.*//g' | sort | uniq -c | sort -rn > url_hits.txt
@Kurukshetran
Kurukshetran / IteratecStatisticalLoggingSessionEventListener.java
Created April 9, 2019 08:12 — forked from icyerasor/IteratecStatisticalLoggingSessionEventListener.java
An Hibernate StatisticalLogging EventListener that uses seconds instead of nanoseconds for logging
package de.iteratec;
import org.hibernate.BaseSessionEventListener;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Modified to make the output remotely readable; directly use the slf4jLogger we use in our project.
* Use by calling sessionFactory.getSessionFactoryOptions().getBaselineSessionEventsListenerBuilder().setAutoListener(IteratecStatisticalLoggingSessionEventListener.class);
@Kurukshetran
Kurukshetran / gist:83aa22b995e9e305b6fb226398cb3146
Created April 8, 2019 09:12 — forked from alder/gist:1420a45c19cb947e03ce
Manually read CSV data in JMeter witn BeanShell
import java.text.*;
import java.io.*;
import java.util.*;
String filename = "oprosnik_" + vars.get("fileNum") + ".csv";
ArrayList strList = new ArrayList();
try {
File file = new File(filename);