From 3994aa8cf1bdcf3a07cddfefdb96cc2b94e01a97 Mon Sep 17 00:00:00 2001 From: Prasanna Kumar Kalever Date: Thu, 1 Jun 2017 00:31:45 +0530 Subject: cache: implement LRU cache to hold glfs objects Problem: ------- 1. Currently, each cli command take ~5 secs for execution. The Maximum latency is due to initializing a glfs object (glfs_init() and friends). 2. OOM kills due to glfs_fini() leaks (~10MB per object) Solution: -------- Caching bipasses glfs_init() calls from the very next command, as in the first command it goes via the glfs_init route, since there will be cache miss. Hence with caching cli command on a local machine should take ~1 sec. ATM, the cache query looks at the volume name only, as the host name will be localhost in our case and transport will be tcp 24007 always. The default cache capacity is 5 i.e there can be a max of five glfs entries in the cache, anything more will lead to release of least recently used object. This way, if there are <= 5 volume in use for block, there will be no glfs_fini() calls, hence no leaks, no OOM's. The next patch will help in making cache capacity configurable. Change-Id: Ia891451cb92cf09959c1aff85976d78302ec7014 Signed-off-by: Prasanna Kumar Kalever [ndevos: correct compiling+linking against libgfapi.so] --- rpc/glfs-operations.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'rpc/glfs-operations.c') diff --git a/rpc/glfs-operations.c b/rpc/glfs-operations.c index 9ae8ec5..72de38f 100644 --- a/rpc/glfs-operations.c +++ b/rpc/glfs-operations.c @@ -20,6 +20,10 @@ glusterBlockVolumeInit(char *volume, int *errCode, char **errMsg) struct glfs *glfs; int ret; + glfs = queryCache(volume); + if (glfs) { + return glfs; + } glfs = glfs_new(volume); if (!glfs) { @@ -67,6 +71,12 @@ glusterBlockVolumeInit(char *volume, int *errCode, char **errMsg) goto out; } + if (appendNewEntry(volume, glfs)) { + *errCode = ENOMEM; + LOG("gfapi", GB_LOG_ERROR, "allocation failed in appendNewEntry(%s)", volume); + goto out; + } + return glfs; out: -- cgit