From 81417ae4a5a58ef75ac4113ea2b2d8c72474ea97 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Tue, 25 Nov 2014 23:11:41 +0000 Subject: [PATCH] caclulate the total amount of time spent writing an object out In order to calculate the writeout bandwidth we need to know how long it took to write the data to peristant storage in addition to how much was written. --- content/llcache.c | 59 +++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/content/llcache.c b/content/llcache.c index c786ad02d..e97beb97e 100644 --- a/content/llcache.c +++ b/content/llcache.c @@ -2301,11 +2301,16 @@ build_candidate_list(struct llcache_object ***lst_out, int *lst_len_out) * \return NSERROR_OK on success or appropriate error code. */ static nserror -write_backing_store(struct llcache_object *object, size_t *written_out) +write_backing_store(struct llcache_object *object, size_t *written_out, unsigned long *elapsed) { nserror ret; uint8_t *metadata; size_t metadatasize; + struct timeval start_tv; + struct timeval end_tv; + struct timeval elapsed_tv; + + gettimeofday(&start_tv, NULL); /* put object data in backing store */ ret = guit->llcache->store(object->url, @@ -2338,10 +2343,16 @@ write_backing_store(struct llcache_object *object, size_t *written_out) guit->llcache->invalidate(object->url); return ret; } + gettimeofday(&end_tv, NULL); + + timersub(&end_tv, &start_tv, &elapsed_tv); + object->store_state = LLCACHE_STATE_DISC; *written_out = object->source_len + metadatasize; + *elapsed = (elapsed_tv.tv_sec * 1000) + (elapsed_tv.tv_usec / 1000); + return NSERROR_OK; } @@ -2358,30 +2369,34 @@ static void llcache_persist(void *p) struct llcache_object **lst; int lst_count; int idx; + unsigned long total_elapsed = 0; + unsigned long elapsed; ret = build_candidate_list(&lst, &lst_count); - if (ret == NSERROR_OK) { - /* obtained a candidate list, make each object - * persistant in turn - */ - for (idx = 0; idx < lst_count; idx++) { - ret = write_backing_store(lst[idx], &size_written); - if (ret != NSERROR_OK) { - break; - } - total_written += size_written; - - if (total_written > llcache->bandwidth) { - /* The bandwidth limit has been reached. - * Writeout scheduled for the remaining objects - */ - guit->browser->schedule(1000, llcache_persist, NULL); - break; - } - } - - free(lst); + if (ret != NSERROR_OK) { + LOG(("Unable to construct candidate list for persisatnt writeout")); + return; } + + /* obtained a candidate list, make each object persistant in turn */ + for (idx = 0; idx < lst_count; idx++) { + ret = write_backing_store(lst[idx], &size_written, &elapsed); + if (ret != NSERROR_OK) { + break; + } + total_written += size_written; + total_elapsed += elapsed; + + if (total_written > llcache->bandwidth) { + /* The bandwidth limit has been reached. + * Writeout scheduled for the remaining objects + */ + guit->browser->schedule(1000, llcache_persist, NULL); + break; + } + } + + free(lst); }