I am working on a distributed computing project and I want to run fewer tasks on computers that are virtual machines. How can I detect the hypervisor
flag from the CPU in C#?
I know there are lots of answers that involve checking the motherboard manufacturer, display adapter, or MAC address for certain strings, but those seem like fragile implementations.
Those fragile implementations seem like your best bet. Languages like C# and Java were never really intended to run close enough to bare metal to easily enable robust implementations of runtime bare metal interactions, hence the lack of pointers and automatic GC. Modern VM implementations actually are supposed to even make it difficult for you to tell you're running on a VM in the first place.
That said, if you know the hypervisor IP addresses (as the link suggests you could), you could check the IP of the request and deal with it accordingly, provided of course that the IP of your hypervisor is static or you know the exact range of IP addresses it could have.
PS: Going further, you could also make a list of all IPs -- again, if they're static -- and write your own load balancer of sorts to direct the traffic as you wish. Although, I'm just curious, why are you trying to offload tasks from VMs? Are there computationally intensive tasks for which you want to cut out as much overhead as possible?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With