skip to Main Content

I have two GCE instances: one with a COS image running CentOS 7 in a container. Let’s call it VM1. And another with a CentOS 7 image directly on it. Let’s call it VM2. Both of them run the same PHP app (Laravel).

VM1
 Image: COS container with CentOS 7
 Type: n1-standard-1 (1 vCPUj, 3,75 GB)
 Disk: persistent disk 10 GB

VM2
 Image: CentOS 7
 Type: n1-standard-1 (2 vCPUj, 3,75 GB)
 Disk: persistent disk 20 GB

As you can see, VM2 has a slightly better spec than VM1. So it should perform better, right?

That said, when I request an specific endpoint, VM1 responds in ~ 1.6s, while VM2 responds in ~ 10s. It’s about 10x slower. The endpoint does exactly the same thing on both VMs, it queries the data base on a GCP SQL instance, and returns the results. Nothing abnormal.

So, it’s almost the same hardware, it’s the same guest OS and the same app. The only difference is that the VM1 is running the app via Docker.

I search and tried to debug many things but have no idea of what is going on. Maybe I’m misunderstanding something.

My best guess is that the COS image has some optimization that makes the app execution faster. But I don’t know what exactly. Firstly I thought it could be some disk IO problem. But the disk utilization is OK on VM2. Then I thought it could be some OS configuration, then I compared the sysctl settings of both VMs and there’s a lot of differences, as well. But I’m not sure what could be the key for optimization.

My questions are: why is this difference? And what can I change to make VM2 as faster as VM1?

2

Answers


  1. First of all, Container-Optimized OS is based on the open-source Chromium OS, it is not CentOS, basically it is another Linux distribution.

    Having said that, you need to understand that this OS is optimized for running Docker containers.

    It means that Container-Optimized OS instances come pre-installed with the Docker runtime and cloud-init and basically that is all that this OS contains, because it is a minimalistic container-optimized operating system.

    So, this OS doesn’t waste resources with all the applications, libraries and packages that CentOS have that can consume extra resources.

    I have installed both OSs in my own project to check the Disk usage of each OS, and Container-Optimized OS from Google only uses 740MB, and CentOS consumes 2.1GB instead.

    $ hostnamectl | grep Operating
    Operating System: Container-Optimized OS from Google
    
    $ df -h
    Filesystem      Size  Used Avail Use% Mounted on
    /dev/root       1.2G  740M  482M  61% /
    
    $ hostnamectl | grep Operating
    Operating System: CentOS Linux 7 (Core)
    
    $ df -h
    /dev/sda2        20G  2.1G   18G  11% /
    

    I wasn’t able to use a small persistent disk with CentOS, the minimum is 20 GB.

    On the other hand, containers let your apps run with fewer dependencies on the host virtual machine (VM) and run independently from other containerized apps that you deploy to the same VM instance and optimize the resources used.

    Login or Signup to reply.
  2. I don’t have many experience with GCP (just Azure and AWS), but this problem maybe about latency. So You need confirm if all your assets are in the same region.

    You can try to verify the time to response from each VM to your BD. With this information you will be able to know if this situation is about of latency or not.

    https://cloud.google.com/compute/docs/regions-zones/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search