Home > OS >  Why is Google Compute Engine's compute-optimized CPU slower than a laptop on number crunching i
Why is Google Compute Engine's compute-optimized CPU slower than a laptop on number crunching i

Time:05-06

I am running the following code both on my Precision 5520 laptop and on Google Compute Engine's c2-standard-4:

import multiprocessing as mp
import time

def foo():
    before = time.time()
    sum = 0
    for i in range(1, 100000000):
        sum  = i
    print(time.time() - before, sum)

for i in range(mp.cpu_count()):
    mp.Process(target=foo).start()

In both cases, mp.cpu_count() is 4. However, unexpectedly to me, each computation on the laptop takes 5.2 seconds, while it takes 8.6 seconds on GCE.

The laptop runs Xeon E3-1505M v6 @ 3GHz. It is a strong CPU, but I would expect that a laptop CPU cannot compare with a CPU at a Google HPC server (e.g. because of heat limitations).

Python version on the laptop is 3.8.5. GCE has Python version 3.9.2.

Why could that be the case?

Update Following the reply by @John Hanley, I changed the configuration at Google Cloud Platform, so it uses only one vCPU per core and the time is now 4 seconds instead of 8.6. This is astonishing, as it seems to undermine the whole idea of using hyper-threads...

CodePudding user response:

On your laptop, each CPU core is two Hyper-Threads.

In the cloud, one virtualized CPU (vCPU) is one Hyper-Thread.

Your laptop, given the same motherboard, clock speed, memory, etc has two times the equivalent CPU power per CPU. When you configure a VCPU in the cloud you are configuring one-half of a physical CPU core.

On Compute Engine, each virtual CPU (vCPU) is implemented as a single hardware multithread on one of the available CPU processors. On Intel Xeon processors, Intel Hyper-Threading Technology supports multiple app threads running on each physical processor core. You configure your Compute Engine VM instances with one or more of these multithreads as vCPUs. The specific size and shape of your VM instance determines the number of its vCPUs.

Google Cloud CPU Platforms

  • Related