move the low bandwidth check to allow for an average over a much longer time

This commit is contained in:
Vincent Sanders 2014-12-03 20:13:10 +00:00
parent 0f6f0a0169
commit 5bf4b3ff2b

View File

@ -31,8 +31,6 @@
* *
* \todo Improve writeout bandwidth limiting. * \todo Improve writeout bandwidth limiting.
* *
* \todo Implement minimum writeout bandwidth limit.
*
*/ */
#include <stdlib.h> #include <stdlib.h>
@ -228,28 +226,47 @@ struct llcache_s {
/** The target upper bound for the RAM cache size */ /** The target upper bound for the RAM cache size */
uint32_t limit; uint32_t limit;
/** The minimum lifetime to consider sending objects to /** Whether or not our users are caught up */
* backing store. bool all_caught_up;
/* backing store elements */
/**
* The minimum lifetime to consider sending objects to backing
* store.
*/ */
int minimum_lifetime; int minimum_lifetime;
/** The time over which to apply the bandwidth calculations in ms */ /**
* The time over which to apply the bandwidth calculations in ms
*/
unsigned long time_quantum; unsigned long time_quantum;
/** The minimum bandwidth to allow the backing store to use in /**
* The minimum bandwidth to allow the backing store to use in
* bytes/second. Below this the backing store will be * bytes/second. Below this the backing store will be
* disabled. * disabled.
*/ */
size_t minimum_bandwidth; size_t minimum_bandwidth;
/** The maximum bandwidth to allow the backing store to /**
* use in bytes/second * The maximum bandwidth to allow the backing store to use in
* bytes/second
*/ */
size_t maximum_bandwidth; size_t maximum_bandwidth;
/**
* Total number of bytes written to backing store.
*/
uint64_t total_written;
/**
* Total nuber of miliseconds taken to write to backing store.
*/
uint64_t total_elapsed;
/** Whether or not our users are caught up */
bool all_caught_up;
}; };
/** low level cache state */ /** low level cache state */
@ -257,6 +274,7 @@ static struct llcache_s *llcache = NULL;
/* forward referenced callback function */ /* forward referenced callback function */
static void llcache_fetch_callback(const fetch_msg *msg, void *p); static void llcache_fetch_callback(const fetch_msg *msg, void *p);
/* forward referenced catch up function */ /* forward referenced catch up function */
static void llcache_users_not_caught_up(void); static void llcache_users_not_caught_up(void);
@ -266,11 +284,11 @@ static void llcache_users_not_caught_up(void);
******************************************************************************/ ******************************************************************************/
/** /**
* Create a new object user * Create a new object user.
* *
* \param cb Callback routine * \param cb Callback routine.
* \param pw Private data for callback * \param pw Private data for callback.
* \param user Pointer to location to receive result * \param user Pointer to location to receive result.
* \return NSERROR_OK on success, appropriate error otherwise * \return NSERROR_OK on success, appropriate error otherwise
*/ */
static nserror llcache_object_user_new(llcache_handle_callback cb, void *pw, static nserror llcache_object_user_new(llcache_handle_callback cb, void *pw,
@ -2378,6 +2396,26 @@ write_backing_store(struct llcache_object *object,
return NSERROR_OK; return NSERROR_OK;
} }
/**
* Check for overall write performance.
*
* If the overall write bandwidth has fallen below a useful level for
* the backing store to be effective disable it.
*
* \param p The context pointer passed to the callback.
*/
static void llcache_persist_slowcheck(void *p)
{
unsigned long total_bandwidth; /* total bandwidth */
total_bandwidth = (llcache->total_written * 1000) / llcache->total_elapsed;
if (total_bandwidth < llcache->minimum_bandwidth) {
LOG(("Cannot write minimum bandwidth"));
warn_user("LowDiscWriteBandwidth", 0);
guit->llcache->finalise();
}
}
/** /**
* Possibly write objects data to backing store. * Possibly write objects data to backing store.
* *
@ -2402,7 +2440,7 @@ static void llcache_persist(void *p)
ret = build_candidate_list(&lst, &lst_count); ret = build_candidate_list(&lst, &lst_count);
if (ret != NSERROR_OK) { if (ret != NSERROR_OK) {
LOG(("Unable to construct candidate list for persisatnt writeout")); LLCACHE_LOG(("Unable to construct candidate list for persisatnt writeout"));
return; return;
} }
@ -2419,7 +2457,8 @@ static void llcache_persist(void *p)
total_written += written; total_written += written;
total_elapsed += elapsed; total_elapsed += elapsed;
total_bandwidth = (total_written * 1000) / total_elapsed; total_bandwidth = (total_written * 1000) / total_elapsed;
LOG(("Wrote %d bytes in %dms bw:%d %s",
LLCACHE_LOG(("Wrote %d bytes in %dms bw:%d %s",
written, elapsed, (written * 1000) / elapsed, written, elapsed, (written * 1000) / elapsed,
nsurl_access(lst[idx]->url) )); nsurl_access(lst[idx]->url) ));
@ -2433,9 +2472,13 @@ static void llcache_persist(void *p)
* object was very large. * object was very large.
*/ */
if (total_bandwidth < llcache->minimum_bandwidth) { if (total_bandwidth < llcache->minimum_bandwidth) {
LOG(("Cannot write minimum bandwidth")); /* Writeout was slow in this time quantum.
warn_user("LowDiscWriteBandwidth", 0); * Schedule a check in the future to see if
guit->llcache->finalise(); * overall performance is too slow to be useful.
*/
guit->browser->schedule(llcache->time_quantum * 100,
llcache_persist_slowcheck,
NULL);
break; break;
} else { } else {
if (total_bandwidth > llcache->maximum_bandwidth) { if (total_bandwidth > llcache->maximum_bandwidth) {
@ -2478,10 +2521,13 @@ static void llcache_persist(void *p)
} }
} }
LOG(("writeout size:%d time:%d bandwidth:%dbytes/s", llcache->total_written += total_written;
llcache->total_elapsed += total_elapsed;
LLCACHE_LOG(("writeout size:%d time:%d bandwidth:%dbytes/s",
total_written, total_elapsed, total_bandwidth)); total_written, total_elapsed, total_bandwidth));
LOG(("Rescheduling writeout in %dms", next)); LLCACHE_LOG(("Rescheduling writeout in %dms", next));
guit->browser->schedule(next, llcache_persist, NULL); guit->browser->schedule(next, llcache_persist, NULL);
} }
@ -3225,7 +3271,9 @@ llcache_initialise(const struct llcache_parameters *prm)
void llcache_finalise(void) void llcache_finalise(void)
{ {
llcache_object *object, *next; llcache_object *object, *next;
unsigned long total_bandwidth; /* total bandwidth */
total_bandwidth = (llcache->total_written * 1000) / llcache->total_elapsed;
/* Clean uncached objects */ /* Clean uncached objects */
for (object = llcache->uncached_objects; object != NULL; object = next) { for (object = llcache->uncached_objects; object != NULL; object = next) {
llcache_object_user *user, *next_user; llcache_object_user *user, *next_user;
@ -3271,6 +3319,9 @@ void llcache_finalise(void)
/* backing store finalisation */ /* backing store finalisation */
guit->llcache->finalise(); guit->llcache->finalise();
LOG(("Backing store average bandwidth %lu bytes/second",
total_bandwidth));
free(llcache); free(llcache);
llcache = NULL; llcache = NULL;
} }