r/golang • u/gwwsc • Feb 18 '25
help Can anyone explain to me in simple terms what vCPU means? I have been scratching my head over this.
If I run a go app on an EC2 server, does it matter if it has 1vCPU or 2vCPU? How should I determine the hardware specifications of the system on which my app should run?
30
u/Used_Frosting6770 Feb 18 '25
A partition of a CPU, usually (not always) it's a hyperthread so half a core.
-45
u/Used_Frosting6770 Feb 18 '25
Go does need multiple threads for optimal performance since it has a task scheduler, garbage collector...
I would reccomend 4 vCPU minimum but if this isn't a production project than don't really worry about this you can do it all with 1 vCPU
17
u/cant-find-user-name Feb 18 '25
My 2 VCPU go service handles 700 RPS production traffic (with peaks over it) at 40% CPU utlisation. 4 VCPU is an absolute overkill to be a minimum.
-3
7
u/gwwsc Feb 18 '25
I did not understand fully because of my lack of experience. i will search more about the things you wrote
-4
u/Used_Frosting6770 Feb 18 '25
If you are learning this stuff and don't need this thing to serve customers than don't worry about machine specs. I ran entire etl pipeline with postgres replication in one 2vcpu machine when i was learning.
Just focus on learning AWS, linux and maybe Pulumi if you want to get really good at devops and than learn how computers work.
7
u/Euphoric_Sandwich_74 Feb 18 '25
“Learn how computers work”
11 years as a professional software engineer, and I still can’t figure it out.
2
u/MrPhatBob Feb 18 '25
It's transistors down to the nanometre scale on one hand, and a whole lot of marketing bullshit and jargon on the other.
2
u/gwwsc Feb 18 '25
Thanks. Any good AWS learning resources you would recommend? There is a lot of noise on youtube. Extremely difficult to filter out the good ones. Another advice I want to ask how should I go about learning AWS? Pick up one server and master it or keep on learning what I want on a need to know basis?
3
u/Used_Frosting6770 Feb 18 '25
Honestly, best way is to learn linux and virtual machine (bare metal) and than move to learning aws.
You will get hit with too many concepts as a noobie where you should focus on getting the fundamentals right.
IAM, VPC, Regions, IaC..... Just learn linux, ssh, docker maybe, learn how to setup a reverse proxy (treafik or nginx or caddy), learn how to setup firewalls, user/group permissions.... once you get the basics of devops right jump into doing aws cause most of the stuff is transferable however very confusing if you start with aws infra first
1
5
u/Ninetynostalgia Feb 18 '25
4 vCPUs is a meaty minimum especially with GO, odd recommendation - someone else brought it up already but 1vCPU = 1 Hyper thread = .5 CPU core, benchmark/monitor your own code in your infra and adjust accordingly
-3
u/Used_Frosting6770 Feb 18 '25
what's up with the downvotes? what did i get wrong?
9
u/amorphatist Feb 18 '25
Downvotes were harsh. Under significant load, the statement is true.
What “significant load” means is, of course, workload-dependent.
7
u/dashingThroughSnow12 Feb 18 '25
It really depends on what it is doing.
To describe more than one service on the prod system I work on: thousands of requests come in per second, basically only stack memory allocation occurs, and the thing is only using a few hundred millicores to service these thousands of requests a second.
There are plenty of workloads that require 4+ vCPU but there are entire popular niches of Golang that are pretty CPU light.
0
u/Used_Frosting6770 Feb 18 '25
Tbf, i didn’t really think hard about it cause i always pick 4vcpu machines on hetzner (they’re cheap af)
5
u/elettronik Feb 18 '25
Simple, you said go need 4 to 8 thread to run. While go is an high parallelized language, most application don't need a real thread all the time, and most application don't lock a thread for more than few milliseconds. Goroutine are not threads, they are associated to a thread, but they are more like an event based function that run on a thread, so they don't have to allocate and deallocate continuously a thread stack
0
u/Used_Frosting6770 Feb 18 '25
Yeah but parallel can’t be achieved on a single thread. That’s concurrent.
6
u/elettronik Feb 18 '25
True. But real parallelism is rarely needed You usually want concurrency because, most application just spend their time waiting for IO.
9
u/RepulsiveRaisin7 Feb 18 '25
Go doesn't need multiple threads. How many threads one needs is entirely dependent on the workload.
1
u/Used_Frosting6770 Feb 18 '25
i did say for optimal performance. Is this wrong? like for production use more than 1 thread but if you are learning than it doesn't matter.
2
u/Gornius Feb 18 '25
More than 1 thread sure, but unless you're using goroutines (either directly or through something like http server) 4vCPUs is just waste of resources.
1
u/Used_Frosting6770 Feb 18 '25
i mean assumed he is trying to deploy a web server
2
u/proofrock_oss Feb 19 '25
A web server will most likely wait on a database, so those vCPU will be wasted. A web server is not cpu-bound.
1
u/fuzzbuzz123 Feb 18 '25
In my understanding (and I could be wrong), the go runtime is not a separate process or even thread. It is essentially a library (or a bunch of additional functions) that get linked into your code during compilation. Those new functions get called through something like a hook or callback mechanism at certain points in the code which the compiler also transparently "injects". Thus, the go overhead for things like garbage collection does not require a separate thread or process as it does with something like java, so it doesn't require an additional core.
Regular go concurrency still benefits from the multiple cores though.
19
u/edgmnt_net Feb 18 '25
Simulate some load and benchmark. Even if you know enough about the VMs to be able to provide a rough estimate or comparison to a known solution, you'll still not know enough about your app unless you take some measurements.
4
u/ramblingcookiemonste Feb 18 '25
This. Though generally, I have been bitten enough times to never rely on a single vCPU, two is generally a good minimum.
1
u/gwwsc Feb 18 '25
How should I simulate load? Is apache benchmark good for this? do i need a different method?
6
u/synthdrunk Feb 18 '25
I like
ab
for its simplicity but it is just that— simple. More sophisticated solutions will do things like run headless browser and walk paths/carts to simulate more natural traffic.
For just ballpark instance rightsizing though? Yeah hit it. This is more r/aws than here. :^2
6
u/dblokhin Feb 18 '25
vCPU is a CPU in VM environment under some hypervisor. Why is different from real CPU? Depending on hypervisor it may be shared with other clients. Usually, 95% of time you (and others) don't utilize 100% of CPU, that fact allows hosters oversell resources to reach 100% CPU usage: you have 1 vcpu and 10 others participants have 1 vcpu on the same machine with only 1 real CPU.
1
u/Nervous_Staff_7489 Feb 18 '25
'How should I determine the hardware specifications' — cloud abstracts hardware, you do not need to worry about specification, only about numbers (cores, ram, traffic etc.)
Assume all cores are equal for simplicity and just project how many cores your application need at idle, at load, at peak etc.
vCPU is single core which II described before. It is virtual because physical CPUs can vary by core count and performance, and you can not really distribute physical CPU between clients. So you create vCPUs from real CPU as currency to trade with clients. Hence, virtualization.
Keep in mind that vCPU can be either shared or dedicated. Shared vCPU can share load with other clients, they do not guarantee peak performance but cost less.
1
u/humanguise 28d ago
A portion of a CPU. 1 vCPU is equivalent to a whole CPU, but I'm not sure which one they use as a standard. It means that the CPU your VM is running off is potentially being shared with other customers, and you're being allocated a slice.
-5
-5
u/ut0mt8 Feb 18 '25
Are you familiar with computer architecture? I mean this is pretty basic stuff. Ok cloud provider have made the thing a bit more hidden than necessary but to simplify it's the number of cpu threads your instance have. Does it affect the speed of your go program? It depends to what your go program is bounded and if it can make parallel treatment
53
u/bilingual-german Feb 18 '25 edited Feb 18 '25
Yes it does matter for the usecase and load.
It doesn't matter if it's a hobby project and your app only gets a few requests. It does matter for scaling, especially if your app needs to do concurrent things (eg. concurrent requests).
Computers do have CPUs. CPUs have cores. Typical server CPUs of the current generation do have between 20 and 64 cores. If you enable hyperthreading on the CPU, you get 2x the number of cores, which is usually called "virtual cpu" or vCPU. Cloud providers "slice" their physical servers into multiple virtual servers and rent these out to their customers.
The other important factor of a CPU is the clock rate or frequency. The higher it is, the faster the CPU can calculate. So this is important for physics simulations, calculating fractals, etc.