Improving my dev workflow - Save thy memory ⚡️

Problem

For my dev flow, I need to run a ringarrow-up-right backend server, figwheelarrow-up-right for frontend hot loading, and a datomicarrow-up-right database. For the uninitiated, each of them is running on a different JVM and now add IntelliJ(curse me for not learning Emacs), a browserarrow-up-right with a million tabs, Spotifyarrow-up-right, Slack, Zoom and there's no difference between a toaster and Macbook.

Although you can control the JVM memory usage, it's easy to run into memory issues and I'm yet to find a decent balance between performance and memory usage.

macOS extensively uses swap to address memory overflow but SSD's lifespan decreases with each write and more importantly, it's slower than RAM, which results in slower operations and workflows.

Solution

Reduce the memory allocation pool by tuning JVM with Xms optionarrow-up-right

Putting all things in a server

Get your code on a 20$ machinearrow-up-right which gives you 2CPUs and 4 gigs of RAM. I found this enough and added more swaparrow-up-right just in case. Setup your Nginx ssl and certificates if any and start the servers.

Connecting to remote machine

You don't want to swap local URLs with server URLs and run the whole process; there's something better i.e ssh port forwardingarrow-up-right. Start port forwarding with this:

ssh -L port-local-1:localhost:remote-port-1 -L port-local-2:localhost:port-local-2 root@server-ip

Every request to localhost:port-1 will forward to server's port-1

Syncing changes

Now for every change you make to your IntelliJ you want to see your changes hot loaded. All intelli-j products have file watchersarrow-up-right. File watchers allow you to run a script when a file is saved, which is exactly what we need. Add a file watcher which rsync'sarrow-up-right your local codebase to remote. A couple of lines of bash

#!/usr/bin/env bash

cd ~/Documents
rsync -av proj/ root@server:~/a-folder --delete --exclude=exclude-folder/

And that's it.

Tip: Don't forget to forward your nrepl ports as well.

Although this is very specific to Clojure the key idea is to use an additional dedicated system for your computation and make it seem like your local machine is the dedicated machine.

Skip upgrading to an expensive macbook and get a cheap server(take advantage of promo credits😬)

Cadjakenvelope CMarrow-up-right

Last updated