Skip to main content

Posts

Load testing with Java: Pound on a resource with multiple threads

Load testing involves multiple threads or processes performing operations against a resource. For example, execute a query against a database server via 50 concurrent threads. The tricky part is waiting for the threads to start up before the commands are actually executed, in order to make sure that the resource is truly getting hammered. Here's an example of how to accomplish this in Java. It is possible to refactor the following code into a utility accepts two parameters: the number of threads and a lambda expression which can be passed as a Runnable object. final int numThreads = 50; ExecutorService executor = Executors.newFixedThreadPool(numThreads); CountDownLatch ready = new CountDownLatch(numThreads); CountDownLatch start = new CountDownLatch(1); CountDownLatch done = new CountDownLatch(numThreads); for (int j = 0 ; j < numThreads ; j++) {    executor.execute(() -> { ready.countDown(); try {    start.await(); /...

Running 2560x1080 on LG 29UM57-P on an old MacBook Pro OSX El Capitan

Yes. A mid-2011 MacBook Pro running OSX El Capitan can drive a 2560x1080 monitor via HDMI. I was not able to get 60 Hz working. I am settling with 53 Hz. I tried many settings before finding something that works. The refresh rate seems fine to me. Maybe the text could be clearer but for a $200 monitor running this resolution, I'll take it. Apple MacBook 2015 retina resolution is 2560 x 1800. Consider buying a better monitor that may literally give you fewer headaches. Install  SwitchResX Follow the instructions for disabling SIP After rebooting, run SwitchResX via System Preferences Select your LG monitor Click Custom Resolutions Click the + icon  Enter these settings  ( source ) Exit SwitchResX and save Reboot Run SwitchResX via System Preferences Select your LG monitor Click Current Resolutions Select the 2560x1080, 53 Hz setting Enable SIP If you discover better settings, please leave a comment.

Use pstree instead of ps

pstree -alp This magic incantation displays the process list as a tree, showing process IDs (-p) and arguments (-a), on lines long enough to fully show all the arguments (-l). Make it part of your toolbox! You can remember this command via the phrase process-tree-Alps! You're welcome!

Monitor changes in available disk space

for (;;) {         @x = `df /common`;         @y = ($x[2]=~ /(\d+)/g);         $avail = $y[2];         if ($last) {                 my $delta = $avail - $last;                  print "$delta";         }         print $x[2];         $last = $avail;         sleep 5; }

An ingenious way to find Java on POSIX systems

This is Perl code. _java_bin returns the full path to the java executable. From http://search.cpan.org/~dolmen/DateTime-TimeZone-HPUX-1.04/lib/DateTime/TimeZone/HPUX.pm our @JAVA_HOMES = ( '/opt/java1.4', ); { my $_java_bin; sub _java_bin { return $_java_bin if defined $_java_bin; $_java_bin = ''; # Default value: java not found (false) foreach ( (map { ("$_/jre/bin/java", "$_/bin/java") } (exists $ENV{JAVA_HOME} ? ($ENV{JAVA_HOME}) : ()), @JAVA_HOMES, ), (map { "$_/java" } split(/:/, $ENV{PATH}) ), ) { next unless -x "$_"; $_java_bin = $_; last; } return $_java_bin; } }

Find the 10 largest directories on POSIX

This script outputs the number of 1,024 byte blocks consumed by each of the 10 largest directories in the provided directory, or in the current directory if no arguments are provided. From: Warren Young Date: Wed, 30 Jan 2013 21:08:33 -0700 "This script helps me find the 10 biggest pigs on any system with a basic POSIX user environment." #!/bin/sh if [ $# -eq 0 ] then     dir=. else     if [ ! -d $1 ]     then         echo usage: $0 [directory] [options]         echo         echo "  Prints kb in use in directory; if directory isn't"         echo "  given, '.' is assumed."         echo         echo "  If you give options, they are passed to du, in addition"         echo "  to the -sk options the script provides."         echo    ...