diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-06-21 21:02:45 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-06-21 21:02:45 +0000 |
commit | 7121694a98f57aab4dd60e683b02a84b907d6ad7 (patch) | |
tree | 38f08a3af89de7d02595f5fa59e1816c0294da3b /src/fs/fs_api.c | |
parent | cce70bba3782e392b4aaf13d144ddc374cc5b1d0 (diff) |
-some more work on probes
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r-- | src/fs/fs_api.c | 77 |
1 files changed, 74 insertions, 3 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c index 8a5b1df766..5c6f373ae5 100644 --- a/src/fs/fs_api.c +++ b/src/fs/fs_api.c @@ -174,10 +174,81 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) break; } } + + /* calculate stop decisions */ + num_probes_change = 0; + num_download_change = 0; + if (h->active_downloads + num_download_waiting > h->max_parallel_requests) + { + if (num_probes_active > 0) + num_probes_change = - GNUNET_MIN (num_probes_active, + h->max_parallel_requests - (h->active_downloads + num_download_waiting)); + else if (h->active_downloads + num_download_waiting > h->max_parallel_requests) + num_download_change = - GNUNET_MIN (num_download_expired, + h->max_parallel_requests - (h->active_downloads + num_download_waiting)); + } + + /* then, check if we should stop some jobs */ + next = h->running_head; + while (NULL != (qe = next)) + { + next = qe->next; + run_time = + GNUNET_TIME_relative_multiply (h->avg_block_latency, + qe->blocks * qe->start_times); + switch (qe->priority) + { + case GNUNET_FS_QUEUE_PRIORITY_PROBE: + /* run probes for at most 1s * number-of-restarts; note that + as the total runtime of a probe is limited to 2m, we don't + need to additionally limit the total time of a probe to + strictly limit its lifetime. */ + run_time = GNUNET_TIME_relative_min (run_time, + GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, + 1 + qe->start_times)); + end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); + rst = GNUNET_TIME_absolute_get_remaining (end_time); + restart_at = GNUNET_TIME_relative_min (rst, restart_at); + if ( (num_probes_change < 0) && + ( (num_probes_expired < - num_probes_change) || + (0 == rst.rel_value) ) ) + { + stop_job (qe); + num_probes_change++; + if (0 == rst.rel_value) + num_probes_expired--; + } + break; + case GNUNET_FS_QUEUE_PRIORITY_NORMAL: + end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); + rst = GNUNET_TIME_absolute_get_remaining (end_time); + restart_at = GNUNET_TIME_relative_min (rst, restart_at); + if ( (num_download_change < 0) && + ( (num_download_expired < - num_download_change) || + (0 == rst.rel_value) ) ) + { + stop_job (qe); + num_download_change++; + if (0 == rst.rel_value) + num_download_expired--; + } + break; + default: + GNUNET_break (0); + break; + } + } + + /* FIXME: calculate start decisions */ + num_probes_change = 0; + num_download_change = 0; + if (h->active_downloads + num_download_waiting < h->max_parallel_requests) + { + num_download_change = num_download_waiting; + num_probes_change = GNUNET_MIN (num_probes_waiting, + h->max_parallel_requests - (h->active_downloads + num_download_waiting)); + } - // FIXME: calculate how many probes/downloads to start/stop - num_probes_change = 42; - num_download_change = 42; next = h->pending_head; while (NULL != (qe = next)) |