Answer the question
In order to leave comments, you need to log in
What happens to a program (Go, Python, JS, PHP) if it needs to allocate memory and the OS runs out of RAM?
Situation:
1. A file is read from the network (disk) in chunks
2. All this is added to a variable
3. The file is large - RAM is running out
4. What will happen to the program (if there are no additional processing)? Will the disk space be allocated (by the operating system)? What if this place is not available anywhere else?
Answer the question
In order to leave comments, you need to log in
The swap file will be involved.
If there is no more space, an out of memory exception will occur and the program will crash.
In general, putting huge files completely in RAM is bad.
It doesn't matter which programming language is used. OS, first of all, will try to serve the appetites of the program. And if the available RAM is not enough, it will get into the swap file / partition (swap).
In Linux, the program will be killed by the OOM protection mechanism as soon as it exceeds a certain threshold of load on system resources. On Windows - I don’t know, maybe it just won’t allocate a critical piece of memory for the application.
And if the program does not know how to handle out-of-memory errors, then it will simply hang or crash with a post-mortem dump.
1. The file is read from the network (disk) in chunksWow, wonderful!
2. It all adds up to a variableWhat?! Why was it needed? It is as if in construction they put a brick house on the foundation as a whole, and not in parts.
Why read it to memory? Why not read from the network directly to disk?
And if your program is 32bit, then you won’t be able to use all the RAM at all if you have more than 3GB of it.
I don’t know how it is on other OSes, but Windows will most likely not highlight it. There is a limit
Depends on how much is required, if a little, then it will be written to the swap, if a lot (I think when the amount of required memory exceeds the swap), then the system may crash. I once decided to test this (I don’t advise doing this), created an array that could take several tens of gigs and started filling it in a loop, as a result, the system crashed with an error (it had 4GB of RAM in total), I tested it on Windows 10 .
In general, thank you all.
In swarm mode in docker, as it turned out, everything crashes with code 137 - it is not allocated to swap by default, in order to stand out, you need to write additional. options. But this is, of course, a moot point - if the application is indomitably gluttonous, then it's pointless.
Read more here:
https://docs.docker.com/config/containers/resource...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question