2

I'm trying to learn about virtualization and containers. In an educational video it is said that the introduction of virtual machines was a big deal because it made companies available to run multiple server instances on the same machine, so they did not have to necessarily buy a new machine just to run a new instance.

But what if I have a Node.js server application? I could run multiple of those on the same machine without any kind of virtualization. Why is even running multiple instances necessary? Why were virtual machines needed? My best guess is that Node.js is designed to support running multiple instances (the instances doesn't "know" about each other), therefore they are not needed, but back then the servers that they used would have "known" about each other if they weren't separated by virtual servers.

Do people do the same using containers? If I have a microservices architecture, and let's say that I only have one computer, am I using containers only to check whether they run correctly in different environments, or do I create multiple of even the same microservice?

Please excuse my sloppy wording, I mainly try to get what is it that I'm actually missing / misunderstanding, and I try to convey my abstract, high-level understanding of the issue.

Link to video: https://youtu.be/JSLpG_spOBM?t=77

1 Answer 1

3

Multiple apps on the same server

But what if I have a Node.js server application? I could run multiple of those on the same machine without any kind of virtualization.

Yes, you can run multiple apps or multiple instances of the same app on a server. The problem is that these apps will interfere.

Some examples of resources, that might interfere:

  • They would all like to listen to the same port e.g. 8080.
  • If they need more memory, they will eventually fight about the same memory.
  • If the apps is busy, they will fight about the same CPU resource.
  • They all would like to write logs to the same files on the file system.
  • They all might want to save data to the same place on the file system.

This needs to be managed in some way, and we don't want to do it manually.

With Virtual Machines on the same server, or Containers on the same server, each instance get its own IP-address, each instance can listen to what port it wants, e.g. all can listen to 8080. You can bound how much memory an instance has, e.g. 1GB - so if an app leaks memory, it does not affect the others. You can also bound how much CPU each instance can use, so they only use their fair share. Each instance has its own view of the filesystem, so all instances can write to the same path (as they see it) - even though it is technically different places.

Multiple instances - Availability

Why is even running multiple instances necessary?

What would you do when you need to patch the server and need to restart it? How will you upgrade your app to a new version? What happens if the hardware on your server crash? What happens when your single instance can not handle all the traffic?

The answer to all those questions, typically is: run more than one instance of your app, and let a load balancer forward the traffic to your instances that are alive.

Why virtualization?

Why were virtual machines needed?

They are not really needed. This is more about economics, a way to use your expensive hardware more efficiently.

If you start a new project, but a server - the server is very powerful and expensive. If you only start a Node.js app on this server, it will probably take long time before this Node.js app is so popular that it need to use the full server. It would be better if you could rent only a small part of the server in the beginning - that is how the Cloud with AWS and Google Cloud Platform works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.