How to Stop WSL2 from Hogging All Your Ram With Docker

I have been doing some performance testing using Docker, Docker-Compose. I was running into an issue, my Dev laptop was showing that Docker (vmmem) was using 90% of my system RAM. That is not great, nor what I want when running performance tests. Several times during my tests my system literally crashed and died :).

WSL2 (Windows Subsystem for Linux 2) has a host of performance benefits for everyone doing Linux related work on Windows. For me personally, it has significant performance benefits in Docker. My docker-compose usages feel snappier and my containers come up about 50% quicker.

The only downside of this, is that previously, I was using a Hyper-V image that ran my Docker engine. This is just how things work when using Docker on Windows. Of course, when you are using this solution, you can just limit the CPU’s and memory on the Docker virtual machine.

With WSL2 however, this explicitly doesn’t create a virtual machine that you can configure in Hyper-V.

The upside of this is that it’s a lot more performant. The downside is that in my experience, WSL2 will happily consume all your memory and CPU and pretty much starve out the host operating system, making all your Docker work really grindy and slow. The reason why is because you start your Docker containers on WSL2 through docker compose, and it seems like it just builds your images and hosts them while provisioning 100% of your computer’s resources to those environments. My observation, pretty quickly your host OS runs out of RAM and so do your containers, and everything drags to a crawl. Fortunately it seems pretty easy to fix.

Setting boundaries for WSL2

We need to set some reasonable resource constraints on what WSL2 can actually use. Fortunately, that’s as simple as going to c:\users\<your your profile name> and creating a .wslconfig file. On my setup, a Dell Precision 5550, i7-10750H CPU @ 2.6GHz, 1 socket, 6 cores, 12 logical processors with 32 GB RAM mine looks like this:

[wsl2]
memory=4GB # Limits VM memory in WSL 2 to 4 GB
processors=5 # Makes the WSL 2 VM use two virtual processors

Now you can restart docker. After a full restart of Docker, let’s checkout the Vmmem process.

Now you should be able to use Docker on your Windows 10 machine without having it use every ounce of available resources.

Water Softener Maintenance

Hey, so our water softener stopped working. Time to roll up the sleeves. Let’s start with R&D.

Problem

  • Common signs of hard water shows up in the dish washer, kettle, water taps etc.,.
  • Water softener system is holding water, when it should normally release the salted water into your house (inlet)

R&D

  • Get the make and model name of your water softener
  • Look up the user guide / user manual
  • Check the troubleshooting guide, this will be product specific!
  • Yes, you can google your problem directly. I choose to start with the product, model and guide first. This helps me avoid rookie videos or tips. No insult to those trying to help!

My recipe

After reading the user manual, specifically the troubleshooting section. My problem was well documented. In a nutshell, the venturi maintenance (see screenshot below), I was able to disassemble, identify the extremely dirty parts. Clean it with vinegar (breaks down mineral build up well). Re-assemble and test. Back in business now.

Special tips:

  • be mindful of the parts, they are small, keep them well organized
  • remember the order, or simply have this diagram handy
  • when washing/cleaning the parts, be sure you don’t loose them. I just put the drain plug in and that worked for me.

Washing/Cleaning

This was simple. I placed all the parts (as illustrated in the screenshot below) in a stainless steel bowl. Sprayed them with vinegar. I let that site for 5 minutes. Scrub each part with a old tooth brush. Rinse all parts with plain water.

Reassembly

This is very simple, but you must follow the diagram, get things reassembled in the correct order.

Special tips:

  • use petroleum jelly to lubricate the O-ring seal. This helps the seal live longer but also seal better, i.e. no air intake!
  • use the access petroleum jelly for the venturi nozzle threads. this helps when you need to remove again, makes it less stuck.