##// END OF EJS Templates
caches: use repo.lru based Dict cache. This LRUDict uses Timing Algo to not have to use locking...
marcink -
r2945:ec5716e4 default
parent child Browse files
Show More
@@ -791,17 +791,6 b' self: super: {'
791 791 license = [ pkgs.lib.licenses.bsdOriginal ];
792 792 };
793 793 };
794 "lru-dict" = super.buildPythonPackage {
795 name = "lru-dict-1.1.6";
796 doCheck = false;
797 src = fetchurl {
798 url = "https://files.pythonhosted.org/packages/00/a5/32ed6e10246cd341ca8cc205acea5d208e4053f48a4dced2b1b31d45ba3f/lru-dict-1.1.6.tar.gz";
799 sha256 = "1k2lhd4dpl6xa6iialbwx4l6bkdzxmzhygms39pvf19x1rk5fm1n";
800 };
801 meta = {
802 license = [ pkgs.lib.licenses.mit ];
803 };
804 };
805 794 "lxml" = super.buildPythonPackage {
806 795 name = "lxml-3.7.3";
807 796 doCheck = false;
@@ -1690,7 +1679,6 b' self: super: {'
1690 1679 self."billiard"
1691 1680 self."kombu"
1692 1681 self."lxml"
1693 self."lru-dict"
1694 1682 self."mako"
1695 1683 self."markdown"
1696 1684 self."markupsafe"
@@ -31,7 +31,6 b' jinja2==2.9.6'
31 31 billiard==3.5.0.3
32 32 kombu==4.2.0
33 33 lxml==3.7.3
34 lru-dict==1.1.6
35 34 mako==1.0.7
36 35 markdown==2.6.11
37 36 markupsafe==1.0.0
@@ -25,15 +25,8 b' and the state of LRU dict.'
25 25 inrae.cache is licensed under LRUDict is licensed under ZPL license
26 26 This software is Copyright (c) Zope Corporation (tm) and
27 27 Contributors. All rights reserved.
28
29 TODO: marcink, we might think of replacing the LRUDict with lru-dict library
30 written in C.
28 """
31 29
32 eg difference in speed:
33
34 LRUDictC Time : 0.00025 s, Memory : 110592 Kb
35 LRUDict Time : 0.00369 s, Memory : 147456 Kb
36 """
37 30 import logging
38 31
39 32 from repoze.lru import LRUCache
@@ -44,8 +37,10 b' log = logging.getLogger(__name__)'
44 37
45 38
46 39 class LRUDict(LRUCache):
47 """ Wrapper to provide partial dict access
48 40 """
41 Wrapper to provide partial dict access
42 """
43
49 44 def __setitem__(self, key, value):
50 45 return self.put(key, value)
51 46
@@ -28,7 +28,8 b' from dogpile.cache.backends import file '
28 28 from dogpile.cache.backends import redis as redis_backend
29 29 from dogpile.cache.backends.file import NO_VALUE, compat, FileLock
30 30 from dogpile.cache.util import memoized_property
31 from lru import LRU as LRUDict
31
32 from rhodecode.lib.memory_lru_dict import LRUDict, LRUDictDebug
32 33
33 34
34 35 _default_max_size = 1024
@@ -41,14 +42,12 b' class LRUMemoryBackend(memory_backend.Me'
41 42
42 43 def __init__(self, arguments):
43 44 max_size = arguments.pop('max_size', _default_max_size)
44 callback = None
45 if arguments.pop('log_max_size_reached', None):
46 def evicted(key, value):
47 log.debug(
48 'LRU: evicting key `%s` due to max size %s reach', key, max_size)
49 callback = evicted
50 45
51 arguments['cache_dict'] = LRUDict(max_size, callback=callback)
46 LRUDictClass = LRUDict
47 if arguments.pop('log_key_count', None):
48 LRUDictClass = LRUDictDebug
49
50 arguments['cache_dict'] = LRUDictClass(max_size)
52 51 super(LRUMemoryBackend, self).__init__(arguments)
53 52
54 53 def delete(self, key):
@@ -111,9 +110,9 b' class CustomLockFactory(FileLock):'
111 110 # waited to much time on a lock, better fail than loop for ever
112 111 log.error('Failed to acquire lock on %s file', self.filename)
113 112 raise
114
115 log.debug('Failed to acquire lock, retry in 0.03')
116 gevent.sleep(0.03)
113 timeout = 0.03
114 log.debug('Failed to acquire lock, retry in %ss', timeout)
115 gevent.sleep(timeout)
117 116
118 117 fcntl.flock = gevent_flock
119 118 return fcntl
@@ -182,8 +182,8 b' setup('
182 182 'rc-ssh-wrapper=rhodecode.apps.ssh_support.lib.ssh_wrapper:main',
183 183 ],
184 184 'beaker.backends': [
185 'memorylru_base=rhodecode.lib.memory_lru_debug:MemoryLRUNamespaceManagerBase',
186 'memorylru_debug=rhodecode.lib.memory_lru_debug:MemoryLRUNamespaceManagerDebug'
185 'memorylru_base=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerBase',
186 'memorylru_debug=rhodecode.lib.memory_lru_dict:MemoryLRUNamespaceManagerDebug'
187 187 ]
188 188 },
189 189 )
General Comments 0
You need to be logged in to leave comments. Login now