Posts

Docker Tools

Machine  takes you from “zero-to-Docker” with a single command. It lets you easily deploy Docker Engines on your computer, on cloud providers, and in your own data center. Read more and download on  Machine’s blog post . Swarm  is native clustering for Docker containers. It pools together several Docker Engines into a single, virtual host. Point a Docker client or third party tool (e.g., Compose, Dokku, Shipyard, Jenkins, the Docker client, etc.) at Swarm and it will transparently scale to multiple hosts. A beta version of Swarm is now available, and we’re working on integrations with Amazon Web Services, IBM Bluemix, Joyent, Kubernetes, Mesos, and Microsoft Azure. Read more on  Swarm’s blog post . Compose  is a way of defining and running multi-container distributed applications with Docker. Back in December we opened up its design to the community. Based on the feedback from that, Compose will be based on Fig, a tool for running development environments with ...

Optimizing your JVM for Best Performance

The better your JVM performs, the better your installation of Tomcat will perform. It's as simple as that. Getting the most out of your JVM is a matter of configuring its settings to match your real-world performance needs as closely as possible. Update your JVM to the latest version, establish some accurate benchmarks so you have a way of quantifying any changes you make, and then get down to business. Effective Memory Management The main thing to consider when tuning your JVM for Tomcat performance is how to avoid wasting  memory  and draining your server's power to process requests. Certain automatic JVM processes, such as garbage collection and memory reallocation, can chew through memory if they occur more frequently than necessary. You can make sure these processes only occur when they need to by using the JAVA_OPTS -Xmx and -Xms switches to control how JVM handles its heap memory. If your JVM is invoking garbage collection too frequently, use the -Xmx switch to ...

Optional References - Java 8

Optional References NulPointers are like  stubbing your toes  - you’ve been doing it since you could stand up, and no matter how smart you are today - chances are you still do. To help with this age-old problem Java 8 is introducing a new template called  Optional<T> .   Borrowing from Scala and Haskell, this template is meant to explicitly state when a reference passed to or returned by a function can be null. This is meant to reduce the guessing game of whether a reference can be null, through over-reliance on documentation which may be out-of-date, or reading code which may change over time. Optional < User > tryFindUser( int userID) { or - void processUser( User user, Optional < Cart > shoppingCart) { The Optional template has a set of functions that make sampling it more convenient, such as isPresent()  to check if an non-null value is available, or   ifPresent()  to which you can pass a Lambda function t...

Controlling OS Processes - Java Runtime.exec()

Launching an OS process from within your code is right there with JNI calls – it’s something you do half-knowing there’s a good chance you’re going to get some unexpected results and some really bad exceptions down the line. Even so, it’s a necessary evil. But processes have another nasty angle to them - they have a tendency to dangle. The problem with launching process from within Java code so far has been that is was hard to control a process once it was launched. To help us with this Java 8 introduces three new methods in the  Process  class - destroyForcibly  - terminates a process with a much higher degree of success than before. isAlive  tells if a process launched by your code is still alive. A new overload for waitFor() lets you specify the amount of time you want to wait for the process to finish. This returns whether the process exited successfully or timed-out in which case you might terminate it. Two good use-cases for these new methods are -...

How to find the Primary Key, Unique Key and Index Indexes in Postgres DB

// For Index SELECT  relname FROM pg_class WHERE oid IN     (SELECT indexrelid FROM pg_index, pg_class        WHERE pg_class.relname='emp'         AND pg_class.oid=pg_index.indrelid         AND indisunique != 't' AND indisprimary != 't'); // For unique SELECT  relname FROM pg_class WHERE oid IN     (SELECT indexrelid FROM pg_index, pg_class        WHERE pg_class.relname='emp'         AND pg_class.oid=pg_index.indrelid         AND indisunique = 't' AND indisprimary != 't'); // For primary SELECT  relname FROM pg_class WHERE oid IN     (SELECT indexrelid FROM pg_index, pg_class        WHERE pg_class.relname='emp'         AND pg_class.oid=pg_index.indrelid         AND indisprimary = 't');

Stamped Locks - Java 8

Multi-threaded code has long been the bane of server developers (just ask Oracle Java Language Architect and concurrency guru  Brian Goetz ). Over time complex idioms were added to the core Java libraries to help minimize thread waits when accessing shared resources. One of these is the classic ReadWriteLock that lets you divide code into sections that need to be mutually exclusive (writers), and sections that don’t (readers). StampedLock has an "optimistic" mode that issues a stamp that is returned by each locking operation to serve as a sort of admission ticket; each unlock operation needs to be passed its correlating stamp. Any thread that happens to acquire a write lock while a reader was holding an optimistic lock, will cause the optimistic unlock to be invalidated (the stamp is no longer valid). At that point the application can start all over, perhaps with a pessimistic lock (also implemented in StampedLock.) Managing that is up to you, and one stamp cannot be us...

SSL Certificate Terminology

SSL has been around for long enough you'd think that there would be agreed upon container formats. And you're right, there are. Too many standards as it happens. So this is what I know, and I'm sure others will chime in. .csr  This is a Certificate Signing Request. Some applications can generate these for submission to certificate-authorities. The actual format is PKCS10 which is defined in  RFC 2986 . It includes some/all of the key details of the requested certificate such as subject, organization, state, whatnot, as well as the  public key  of the certificate to get signed. These get signed by the CA and a certificate is returned. The returned certificate is the public  certificate  ( not  the key), which itself can be in a couple of formats. .pem  Defined in RFC's  1421  through  1424 , this is a container format that may include just the public certificate (such as with Apache installs, and CA certificate files  /etc/...