-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rewrite ddoc_cache to improve performance
There were a couple issues with the previous ddoc_cache implementation that made it possible to tip over the ddoc_cache_opener process. First, there were a lot of messages flowing through a single gen_server. And second, the cache relied on periodically evicting entries to ensure proper behavior in not caching an entry forever after it had changed on disk. The new version makes two important changes. First, entries now have an associated process that manages the cache entry. This process will periodically refresh the entry and if the entry has changed or no longer exists the process will remove its entry from cache. The second major change is that the cache entry process directly mutates the related ets table entries so that our performance is not dependent on the speed of ets table mutations. Using a custom entry that does no work the cache can now sustain roughly one million operations a second with a twenty thousand clients fighting over a cache limited to one thousand items. In production this means that cache performance will likely be rate limited by other factors like loading design documents from disk.
- Loading branch information
Showing
29 changed files
with
2,436 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
% Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
% use this file except in compliance with the License. You may obtain a copy of | ||
% the License at | ||
% | ||
% http://www.apache.org/licenses/LICENSE-2.0 | ||
% | ||
% Unless required by applicable law or agreed to in writing, software | ||
% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
% License for the specific language governing permissions and limitations under | ||
% the License. | ||
|
||
-type dbname() :: iodata(). | ||
-type docid() :: iodata(). | ||
-type doc_hash() :: <<_:128>>. | ||
-type revision() :: {pos_integer(), doc_hash()}. | ||
|
||
-define(CACHE, ddoc_cache_entries). | ||
-define(LRU, ddoc_cache_lru). | ||
-define(REFRESH_TIMEOUT, 67000). | ||
-define(SHUTDOWN_TIMEOUT, 1000). | ||
|
||
-record(entry, { | ||
key, | ||
val, | ||
pid | ||
}). | ||
|
||
-record(opener, { | ||
key, | ||
pid, | ||
clients | ||
}). | ||
|
||
|
||
-ifdef(TEST). | ||
-define(EVENT(Name, Arg), ddoc_cache_ev:event(Name, Arg)). | ||
-else. | ||
-define(EVENT(Name, Arg), ignore). | ||
-endif. |
Oops, something went wrong.