Hi all,

I'm struggling with optimizing resource sharing of MonetDB in production environments (see also: https://www.monetdb.org/pipermail/users-list/2018-June/010276.html).

We run MonetDB instances for several projects / customers on each of our servers. 
Each MonetDB instance is a docker container (used mainly because of ease of deployment and environment isolation). It is not unusual to have 5-10 MonetDB containers on the same server.
In principle, Docker does not even have much to do with this, but it puts everything in a realistic context.


** Memory
mserver5 checks the system memory and calibrates on that. When 10 instances are running, they all assume they have the whole memory for themselves.

Docker allows to set limits on the container memory. It does that by using cgroups (so Docker just makes things easier, but it's really about cgroups).
However, memory limits set by cgroups are not namespaced (https://ops.tips/blog/why-top-inside-container-wrong-memory/#memory-limits-set-by-cgroups-are-not-namespaced). 
This means that each container will still see the whole memory and will simply get killed when the container limit has been reached (definitely not a solution). 
So far, the only mechanism I know to obtain the correect behavior is to run actual VMs for MonetDB. But this is very cumbersome and I want to avoid that as much as possible.
Should we let 10 instances believe they each have the whole memory, and let them fight for it? (well, that's what's happening now, and I know for sure it's bad).
Perhaps the solution can be as easy as allowing an explicit max memory setting, together with some documentation on the consequences of using low / high values.

** CPU
Again, Docker allows to set quotas per container. I think cgroups CPU limits are namespaced, so perhaps this would just work well, I haven't really tried yet.

** I/O
Same issue. It would be ideal to be able to set priorities, so that mserver5 instances that do background work get a lower I/O priority than instances serving online queries.
Also, recommendations on swap settings would be interesting. How much swap? How to tune swappiness kernel settings?

I am very aware that there is no simple answer to most of these questions. Many variables are in the picture.
Still, some general thoughts from the developers would be appreciated.

I think I have read pretty much everything has ever been written about MonetDB, but when it comes to resource utilization I have always bumped into the very unrealistic assumption that each MonetDB instance has a whole server for itself.
As I mentioned above, things could get already much better with simple improvements, like allowing to set the maximum memory usable by each instance.

But more in general, I feel there is much need for some guidelines for production environments. Or at least, to start the discussion.

Best regards, 
Roberto