Skip to content

Instantly share code, notes, and snippets.

View svanoort's full-sized avatar

Sam Van Oort svanoort

  • Toronto, ON, Canada
View GitHub Profile
@svanoort
svanoort / CollectionTest.java
Last active August 11, 2022 14:10
Java Microbenchmarks
package hudson.cli;
import org.junit.Test;
import java.util.*;
// Micro benchmark different array ops in Java
// Originally started from http://stackoverflow.com/questions/322715/when-to-use-linkedlist-over-arraylist/7507740#7507740
// Now completely rewritten to correctly warm up the JIT compilation and take an average over many runs
// Tweaked/corrected version from http://stackoverflow.com/questions/322715/when-to-use-linkedlist-over-arraylist/7507740#7507740
@svanoort
svanoort / gist:532a6918389b3a0e9dd4
Created March 18, 2016 13:11
Tuning Java for minimal memory footprint
One source: http://developers.redhat.com/blog/2014/07/22/dude-wheres-my-paas-memory-tuning-javas-footprint-in-openshift-part-2/
# Set the XMX to cap your max heap, set the xms to a reasonable minimum
-Xmx384m -Xms100m
# No more than 40% of heap free, lowest GC overhead and keeps heap small - still under 0.5% GC time
seropt:
-XX:+UseSerialGC -XX:MinHeapFreeRatio=20 -XX:MaxHeapFreeRatio=40
# parallel version, allows up to 4% time spent on GC, generally uses heap more efficiently, but at cost of 2x the CPU USE
@svanoort
svanoort / speedtest-restart.sh
Last active July 3, 2022 01:56
Do a bash speedtest and reboot router if under 5 MBit
#!/bin/bash
# Curl the bandwidth test site for 10 MB file and get speed in bytes/second, reboot cable modem if <5 MBit
# Useful as bash alias that retests and triggers every hour:
# alias continuously_speedtest='while [ true ]; do echo "Sleeping 1 hour and then speedtesting network"; sleep 3600; bash ~/speedtest-restart.sh; done'
set -o pipefail
echo 'Speedtesting modem now'
DOWN_SPEED=$(curl http://speedtest.wdc01.softlayer.com/downloads/test10.zip -t 100 -o /dev/null -s -w "%{speed_download}" | sed -E "s/\.[0-9]+//g")
if [ "$?" -ne 0 ]; then
echo "Speed test failed!"
@svanoort
svanoort / test-pipelines.groovy
Last active September 30, 2016 01:48
Test mini-pipelines for common problem cases in UI
// Test for handling of errors in nested blocks, and UI rendering of same
stage 'sample'
node {
dir('sample') {
dir('more') {
sh 'failme'
}
}
}
@svanoort
svanoort / analyze-pstools.py
Last active October 20, 2016 18:41
Analyze success pstools dumps to find threads eating a lot of system time
#!/bin/python
import sys
import re
# You'll need to extract JUST the table of pstools output (no headers!) from your pstools thread dumps for windows
print(sys.argv)
if not sys.argv[1] or not sys.argv[2]:
print("Need to supply the path to the pstools before and after filenames")
exit()
@svanoort
svanoort / gcsettings.sh
Last active December 20, 2023 02:27
Blessed GC settings for big servers
# Base settings and GC logging
-server -XX:+AlwaysPreTouch # First should be default, but we make it explicit, second pre-zeroes memory mapped pages on JVM startup -- improves runtime performance
# -Xloggc:gc-%t.log # CUSTOMIZE LOCATION HERE - $path/gc-%t.log -- the %t in the gc log file path is so we get a new file with each JVM restart
-XX:NumberOfGCLogFiles=5 -XX:+UseGCLogFileRotation -XX:GCLogFileSize=20m # Limits the number of files, logs to folder
-XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintHeapAtGC -XX:+PrintGCCause
-XX:+PrintTenuringDistribution -XX:+PrintReferenceGC -XX:+PrintAdaptiveSizePolicy # gather info on object age & reference GC time for further tuning if needed.
# G1 specific settings -- probably should be default for multi-core systems with >2 GB of heap (below that, default is probably fine)
-XX:+UseG1GC
-XX:+UseStringDeduplication
@svanoort
svanoort / idea.vmoptions
Created November 3, 2016 17:56
JVM args for a fast Intellij
# custom IntelliJ IDEA VM options
-server
-Xss16m
-Xms256m
-Xmx1500m
-XX:ReservedCodeCacheSize=240m
-XX:+AlwaysPreTouch
-XX:+TieredCompilation
-XX:+UseCompressedOops
-XX:+UseCompressedClassesPointers