summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoretobi <git@e-tobi.net>2011-10-09 23:20:58 (GMT)
committeretobi <git@e-tobi.net>2011-10-10 00:51:26 (GMT)
commit153e04c08343cade8fff478829a2845092d9cf98 (patch)
tree05fe088b4d6a2fb2d72573b547d3fc7a13d10b3c
parent600533b42ef089086d57d7812eaf74c3fdee64ec (diff)
downloadvdrnfofs-153e04c08343cade8fff478829a2845092d9cf98.tar.gz
vdrnfofs-153e04c08343cade8fff478829a2845092d9cf98.tar.bz2
Added caching
-rw-r--r--HISTORY3
-rw-r--r--TODO1
-rw-r--r--vdrnfofs/nodecache.py28
-rw-r--r--vdrnfofs/vdrnfofs.py6
4 files changed, 35 insertions, 3 deletions
diff --git a/HISTORY b/HISTORY
index 8e2fcdd..5dd34cc 100644
--- a/HISTORY
+++ b/HISTORY
@@ -4,6 +4,9 @@ version 0.8
- Fixed license header in source files - it's the BSD licence now!
- Set mtime of file nodes to recording time (parsed from *.rec)
- Added homepage http://projects.vdr-developer.org/projects/vdrnfofs
+ - Some micro optimizations
+ - Cache the file system nodes user for get_stat() (nodes used for
+ reading are not cached)
version 0.7
- Fixed file/dir node permissions
diff --git a/TODO b/TODO
index 4a9b7e0..8796b4d 100644
--- a/TODO
+++ b/TODO
@@ -1,3 +1,2 @@
- Add option for translating to samba friendly path names
(especially ':')
-- Performance improvement - maybe caching the file system somehow
diff --git a/vdrnfofs/nodecache.py b/vdrnfofs/nodecache.py
new file mode 100644
index 0000000..05cfafa
--- /dev/null
+++ b/vdrnfofs/nodecache.py
@@ -0,0 +1,28 @@
+import time
+
+class NodeCache:
+ class CacheEntry:
+ def __init__(self, node):
+ self.time = time.time()
+ self.node = node
+
+ def __init__(self):
+ self.cache = {}
+ self.last_clean = time.time()
+
+ def get(self, path, creator):
+ #
+ # !!! It might be nicer to have a thread for cleaning the cache, but
+ # with the Fuse option multithreaded = False, threading seems to
+ # be totally impossible. Somehow Fuse blocks ALL threads.
+ #
+ now = time.time()
+ if (now - self.last_clean) > 15:
+ self.cache = dict((k, v) for k, v in self.cache.items() if (now - v.time) <= 10)
+ self.last_clean = now
+
+ cache_entry = self.cache.get(path, None)
+ if not cache_entry or (now - cache_entry.time) > 10:
+ cache_entry = NodeCache.CacheEntry(creator(path))
+ self.cache[path] = cache_entry
+ return cache_entry.node
diff --git a/vdrnfofs/vdrnfofs.py b/vdrnfofs/vdrnfofs.py
index f8f3bda..9f62156 100644
--- a/vdrnfofs/vdrnfofs.py
+++ b/vdrnfofs/vdrnfofs.py
@@ -39,6 +39,7 @@ import logging
from concatenated_file_reader import *
from vdr import *
from filesystemnodes import *
+from nodecache import *
fuse.fuse_python_api = (0, 2)
@@ -108,10 +109,11 @@ class VdrNfoFs(fuse.Fuse):
self.video = ''
self.log = ''
self.loglevel = 'info'
+ self.cache = NodeCache()
def getattr(self, path):
try:
- node = get_node(self.video, path)
+ node = self.cache.get(path, lambda x: get_node(self.video, x))
if node:
return node.get_stat()
return -errno.ENOENT
@@ -122,7 +124,7 @@ class VdrNfoFs(fuse.Fuse):
try:
yield fuse.Direntry('.')
yield fuse.Direntry('..')
- node = get_node(self.video, path)
+ node = self.cache.get(path, lambda x: get_node(self.video, x))
if node:
for item in node.content():
yield fuse.Direntry(item.file_system_name())