You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We can't have the OOM killer wreaking havoc on our users' processes willy-nilly. We need to have a smarter cache memory manager that limits the total cache size per machine to some reasonable number, and allows stealing cache memory between tables. We can discuss the details when we get to this feature.
Additionally, we need to do memory profiling on large queries -- it seems that memory usage is higher than it should be.
Er, hi. This may have been more appropriate on #98, but you could have the cache managed by another process, and communicate with it via some IPC mechanism. When the OOM killer goes hunting, it'll kill the cache process, since it's using a ton of memory, sparing the master process, which will detect the wanton slaughter and spawn a new cache process. Queries will slow down for a second or two during this time, but the system in general was probably already extremely slow due to memory pressure causing frequent page faults (if they have swap on, which a production system shouldn't).
Who knows, you could even have a collection of cache processes, each managing, say, 1GB each, so the OOM killer will only need to sacrifice one of them.
You could also keep the current monolithic process architecture, and set /proc/<pid>/oom_adj to -17 to prevent the OOM killer from ever selecting you, instead choosing something less critical, like a browser. However, you'd have to be absolutely sure you have zero memory leaks, or the system would have no recourse to stop you from eating all the memory, and causing... a kernel panic? I'm honestly not sure what happens.
Sorry if the speculation is unproductive; this is literally the first issue I came across - considering getting involved in the project.
Thanks!! It would be pretty hard to break out the caching system into another process, but it's a really interesting idea.
I think the solution we'll go with here is to limit the cache size on a per-machine basis, and allow tables to steal cache space from each other (this is the way all other db systems with a custom caching scheme do it). This isn't too difficult to do, and really is just a matter of doing it :)
Moving to 1.5 so it doesn't slip through the cracks -- this is pretty important because it's one of the main reasons the OOM killer unleashes on the rethinkdb process and confuses everyone.
This being in backlog once again, I thought I would add my humble suggestion on this.
I believe the problem could be strongly reduced if the following could be implemented:
An interface in the buffer cache to change the max cache size online. I don't think this would be very difficult to do, would it? If the max_size is decreased, the page replacement should be invoked once to actually free the memory.
Exposing an option to the user (ideally in the web UI) to change the cache quota of a table. Other cluster nodes would update their buffer cache instances when receiving the metadata update.
This would already be very useful I think. In fact I believe that making this option configurable at runtime is quite crucial. The current system works for developers, in some cases only just. For anything that's in production, being able to change the cache size would be absolutely crucial I imagine. Plus, - even if you try - you cannot realistically set cache quotas properly when creating the tables, because as soon as you add an additional one, you would run out of memory. Or you might upgrade memory in the machines later on. Or your load might change and different tables might then require different amounts of cache. So currently, the only feasible way is to be extremely conservative on cache values. In many applications, this can degrade performance by magnitudes.
Optionally, one could think about adding quota configurability on a per-machine level. If the cluster is not homogeneous, something like that would be useful. However I suppose that this should be done properly by means of the general overhaul of the cache quota system that @coffeemug initially mentioned, as there are many different configurations and use-cases to be considered.
@danielmewes -- we decided to adopt a simple solution to this. The cache will be capped to some proportion of total available memory (or as set by the user on process startup time), and the tables will steal memory from each other. It's just a matter of doing it, we should be able to get to it ASAP.
@coffeemug Well, that's the more complex solution, as it requires inter-thread communication with all the questions regarding performance and race conditions that come with it. Also it doesn't seem obvious (to me) when one table should "steal" space from another. Should it give it back when the other table needs the memory again? When a request requires cache memory, at what priority should it evict one of its own pages vs. ask another table to provide more memory?
In case you have that all worked out, please ignore my concerns.
If it's easy enough to implement, it's seems like the superior solution. (though there probably are still a handful of cases where the admin would like to specify per-table cache limits or "cache priorities" manually)
I believe that we really really should make the quota reconfigurable for existing tables. This should be very very easy to implement (see #97). The "real" solution which @coffeemug seems to be waiting for to be implemented at some point in the potentially distant future is absolutely non-trivial. Despite that, people might actually prefer explicit control over per-table cache sizes over the magic proposed in the long-term solution.
This issue will have a huge impact on anyone who tries to use RethinkDB for a production system.
The problem being that once you reach a certain table size, your queries will become incredibly slow even on systems with much memory. The only way to make them fast again is to re-create the tables, resulting in downtime and frustration.
On the other hand, you might have a system running absolutely fine for months. Then you add another table and suddenly RethinkDB becomes unusable because it runs out of memory. Again, no chance to do anything about it except for re-creating all of the tables.
We already turn off DIRECT_IO on systems that don't support it (e.g.
encrypted file systems), but there is currently no setting to explicitly
turn it off. Normally you wouldn't want to do that because the RethinkDB
caching system outperforms the page cache for db use cases (because it's
got more information than the page cache). Is there an example use case for
why you might want to turn it off?
once you reach a certain table size, your queries will become incredibly
slow even on systems with much memory
BTW, is there an issue to make the direct-io optional? What if I want the
filsystem cache to serve as a secondary cache?
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/97#issuecomment-19749605
.
Normally you wouldn't want to do that because the RethinkDB
caching system outperforms the page cache for db use cases (because it's
got more information than the page cache).
No, normally I would want to do that because I don't want to micromanage the RethinkDB cache.
The internal cache access is, of course, much faster than a context switch and a copy required to get the page from the filesystem cache (unless, of course, you're memory-mapping), but the operating system might have a lot of memory that I'm not ready to pin to RethinkDB but that might help RethinkDB fetch data from disk under a certain load.
That's the way most databased are implemented, e.g. MySQL, Postgresss, SQLite, Berkeley DB, etc, they all have an internal cache but allow the operating system to help alleviate the disk load using it's large cache as necessary.
Is there an example use case for why you might want to turn it off?
Sure. Suppose I have several databases on a host and batch operations which are going on from cron. If I give most memory to RethinkDB then the cron job using another database will become unnecessary slow, and if I give most memory to the OS then the RethinkDB operations will become unnecessary slow. The usual way to solve this is by letting the OS cache adapt to the load with its LRU or whatever.
Generally, any setup where a RethinkDB table cache is significantly smaller than the filesystem cache can benefit from the secondary caching provided by the OS.
@Tryneus -- I originally thought it should be the same units the user passes on the command line, but I'm not overly attached to that. I think our directory/stats/etc currently have no standard -- they sometimes return bytes, sometimes blocks, sometimes megabytes. We should standardize it all (and will) for monitoring, but for the moment you should use whatever makes the most sense to you.
Activity
alekstorm commentedon Dec 13, 2012
Er, hi. This may have been more appropriate on #98, but you could have the cache managed by another process, and communicate with it via some IPC mechanism. When the OOM killer goes hunting, it'll kill the cache process, since it's using a ton of memory, sparing the master process, which will detect the wanton slaughter and spawn a new cache process. Queries will slow down for a second or two during this time, but the system in general was probably already extremely slow due to memory pressure causing frequent page faults (if they have swap on, which a production system shouldn't).
Who knows, you could even have a collection of cache processes, each managing, say, 1GB each, so the OOM killer will only need to sacrifice one of them.
You could also keep the current monolithic process architecture, and set
/proc/<pid>/oom_adjto-17to prevent the OOM killer from ever selecting you, instead choosing something less critical, like a browser. However, you'd have to be absolutely sure you have zero memory leaks, or the system would have no recourse to stop you from eating all the memory, and causing... a kernel panic? I'm honestly not sure what happens.Sorry if the speculation is unproductive; this is literally the first issue I came across - considering getting involved in the project.
coffeemug commentedon Dec 13, 2012
Thanks!! It would be pretty hard to break out the caching system into another process, but it's a really interesting idea.
I think the solution we'll go with here is to limit the cache size on a per-machine basis, and allow tables to steal cache space from each other (this is the way all other db systems with a custom caching scheme do it). This isn't too difficult to do, and really is just a matter of doing it :)
jdoliner commentedon Feb 7, 2013
This is pretty obviously not going in to 1.4 at this point so I'm going to push it to backlog and we'll see if we can get it in to 1.5.
coffeemug commentedon Feb 12, 2013
Moving to 1.5 so it doesn't slip through the cracks -- this is pretty important because it's one of the main reasons the OOM killer unleashes on the rethinkdb process and confuses everyone.
danielmewes commentedon Apr 27, 2013
This being in backlog once again, I thought I would add my humble suggestion on this.
I believe the problem could be strongly reduced if the following could be implemented:
This would already be very useful I think. In fact I believe that making this option configurable at runtime is quite crucial. The current system works for developers, in some cases only just. For anything that's in production, being able to change the cache size would be absolutely crucial I imagine. Plus, - even if you try - you cannot realistically set cache quotas properly when creating the tables, because as soon as you add an additional one, you would run out of memory. Or you might upgrade memory in the machines later on. Or your load might change and different tables might then require different amounts of cache. So currently, the only feasible way is to be extremely conservative on cache values. In many applications, this can degrade performance by magnitudes.
Optionally, one could think about adding quota configurability on a per-machine level. If the cluster is not homogeneous, something like that would be useful. However I suppose that this should be done properly by means of the general overhaul of the cache quota system that @coffeemug initially mentioned, as there are many different configurations and use-cases to be considered.
coffeemug commentedon Apr 29, 2013
@danielmewes -- we decided to adopt a simple solution to this. The cache will be capped to some proportion of total available memory (or as set by the user on process startup time), and the tables will steal memory from each other. It's just a matter of doing it, we should be able to get to it ASAP.
danielmewes commentedon Apr 30, 2013
@coffeemug Well, that's the more complex solution, as it requires inter-thread communication with all the questions regarding performance and race conditions that come with it. Also it doesn't seem obvious (to me) when one table should "steal" space from another. Should it give it back when the other table needs the memory again? When a request requires cache memory, at what priority should it evict one of its own pages vs. ask another table to provide more memory?
In case you have that all worked out, please ignore my concerns.
If it's easy enough to implement, it's seems like the superior solution. (though there probably are still a handful of cases where the admin would like to specify per-table cache limits or "cache priorities" manually)
danielmewes commentedon Jun 19, 2013
Bump
I believe that we really really should make the quota reconfigurable for existing tables. This should be very very easy to implement (see #97). The "real" solution which @coffeemug seems to be waiting for to be implemented at some point in the potentially distant future is absolutely non-trivial. Despite that, people might actually prefer explicit control over per-table cache sizes over the magic proposed in the long-term solution.
This issue will have a huge impact on anyone who tries to use RethinkDB for a production system.
The problem being that once you reach a certain table size, your queries will become incredibly slow even on systems with much memory. The only way to make them fast again is to re-create the tables, resulting in downtime and frustration.
On the other hand, you might have a system running absolutely fine for months. Then you add another table and suddenly RethinkDB becomes unusable because it runs out of memory. Again, no chance to do anything about it except for re-creating all of the tables.
coffeemug commentedon Jun 19, 2013
This isn't going to make it into the 1.7 sprint, but we'll absolutely make it a part of 1.8.
ArtemGr commentedon Jun 20, 2013
BTW, is there an issue to make the direct-io optional? What if I want the filsystem cache to serve as a secondary cache?
coffeemug commentedon Jun 20, 2013
We already turn off DIRECT_IO on systems that don't support it (e.g.
encrypted file systems), but there is currently no setting to explicitly
turn it off. Normally you wouldn't want to do that because the RethinkDB
caching system outperforms the page cache for db use cases (because it's
got more information than the page cache). Is there an example use case for
why you might want to turn it off?
On Thu, Jun 20, 2013 at 5:42 AM, Artem [email protected] wrote:
ArtemGr commentedon Jun 20, 2013
No, normally I would want to do that because I don't want to micromanage the RethinkDB cache.
The internal cache access is, of course, much faster than a context switch and a copy required to get the page from the filesystem cache (unless, of course, you're memory-mapping), but the operating system might have a lot of memory that I'm not ready to pin to RethinkDB but that might help RethinkDB fetch data from disk under a certain load.
That's the way most databased are implemented, e.g. MySQL, Postgresss, SQLite, Berkeley DB, etc, they all have an internal cache but allow the operating system to help alleviate the disk load using it's large cache as necessary.
Sure. Suppose I have several databases on a host and batch operations which are going on from cron. If I give most memory to RethinkDB then the cron job using another database will become unnecessary slow, and if I give most memory to the OS then the RethinkDB operations will become unnecessary slow. The usual way to solve this is by letting the OS cache adapt to the load with its LRU or whatever.
Generally, any setup where a RethinkDB table cache is significantly smaller than the filesystem cache can benefit from the secondary caching provided by the OS.
coffeemug commentedon Jun 20, 2013
Ok, that makes a lot of sense, thanks for the explanation. See #1051.
89 remaining items
coffeemug commentedon Mar 11, 2014
@Tryneus -- I originally thought it should be the same units the user passes on the command line, but I'm not overly attached to that. I think our directory/stats/etc currently have no standard -- they sometimes return bytes, sometimes blocks, sometimes megabytes. We should standardize it all (and will) for monitoring, but for the moment you should use whatever makes the most sense to you.
coffeemug commentedon Mar 13, 2014
@Tryneus -- what's the state of this issue?
Tryneus commentedon Mar 13, 2014
@coffeemug, I've addressed all the comments in the code review, just waiting from @srh to look at it again.
srh commentedon Mar 17, 2014
I have merged grey_issue_97 into next as of ecf1884.
AtnNn commentedon Mar 18, 2014
I have waited a long time for this! Thanks @srh and @Tryneus.
boltonbytes commentedon Mar 18, 2014
wow is this finally complete? amazingness
coffeemug commentedon Mar 18, 2014
Wow, a year in development. Congrats everyone! (well, we're not quite over the hill yet; still have to ship 1.12)
hokkaido commentedon Mar 19, 2014
Nice!
stuartpb commentedon Apr 10, 2014
Should the FAQ be amended now?
coffeemug commentedon Apr 10, 2014
@stuartpb -- good catch, thanks! I opened a pull request for that -- rethinkdb/docs#261.
robert-zaremba commentedon Jul 7, 2014
http://rethinkdb.com/blog/mongodb-biased-comparison/ - limitations paragraph should be updated.
coffeemug commentedon Jul 7, 2014
Thanks, I opened rethinkdb/docs#403 to track this.
docs: tick rethinkdb#97 board update — RT-BUG-001 dispatched (GLM-5.2…
docs: tick rethinkdb#97 board update — RT-BUG-001 dispatched (GLM-5.2…