aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs_api.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-03-04 22:10:40 +0000
committerChristian Grothoff <christian@grothoff.org>2012-03-04 22:10:40 +0000
commit3470bccc502785d3b4a5c8702afaf78a16114fb0 (patch)
tree42ac2cb33e8dbd8656048a44f69339e1a3e2fbc2 /src/fs/fs_api.c
parent08a8611fba57d6374890a2e6aaa247faae093850 (diff)
downloadgnunet-3470bccc502785d3b4a5c8702afaf78a16114fb0.tar.gz
gnunet-3470bccc502785d3b4a5c8702afaf78a16114fb0.zip
fixing #1927 by further limiting the time a download probe can be active at a time in the download queue; this is equivalent to it having a low priority
Diffstat (limited to 'src/fs/fs_api.c')
-rw-r--r--src/fs/fs_api.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/fs/fs_api.c b/src/fs/fs_api.c
index 64f55e344..81a95c997 100644
--- a/src/fs/fs_api.c
+++ b/src/fs/fs_api.c
@@ -99,6 +99,8 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
99 struct GNUNET_TIME_Absolute end_time; 99 struct GNUNET_TIME_Absolute end_time;
100 100
101 h->queue_job = GNUNET_SCHEDULER_NO_TASK; 101 h->queue_job = GNUNET_SCHEDULER_NO_TASK;
102 restart_at = GNUNET_TIME_UNIT_FOREVER_REL;
103 /* first, see if we can start all the jobs */
102 next = h->pending_head; 104 next = h->pending_head;
103 while (NULL != (qe = next)) 105 while (NULL != (qe = next))
104 { 106 {
@@ -109,7 +111,7 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
109 continue; 111 continue;
110 } 112 }
111 if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) && 113 if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
112 (h->active_downloads + 1 <= h->max_parallel_downloads)) 114 (h->active_downloads < h->max_parallel_downloads))
113 { 115 {
114 start_job (qe); 116 start_job (qe);
115 continue; 117 continue;
@@ -117,7 +119,7 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
117 } 119 }
118 if (h->pending_head == NULL) 120 if (h->pending_head == NULL)
119 return; /* no need to stop anything */ 121 return; /* no need to stop anything */
120 restart_at = GNUNET_TIME_UNIT_FOREVER_REL; 122 /* then, check if we should stop some jobs */
121 next = h->running_head; 123 next = h->running_head;
122 while (NULL != (qe = next)) 124 while (NULL != (qe = next))
123 { 125 {
@@ -125,6 +127,22 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
125 run_time = 127 run_time =
126 GNUNET_TIME_relative_multiply (h->avg_block_latency, 128 GNUNET_TIME_relative_multiply (h->avg_block_latency,
127 qe->blocks * qe->start_times); 129 qe->blocks * qe->start_times);
130 switch (qe->priority)
131 {
132 case GNUNET_FS_QUEUE_PRIORITY_PROBE:
133 /* run probes for at most 1s * number-of-restarts; note that
134 as the total runtime of a probe is limited to 2m, we don't
135 need to additionally limit the total time of a probe to
136 strictly limit its lifetime. */
137 run_time = GNUNET_TIME_relative_min (run_time,
138 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS,
139 1 + qe->start_times));
140 break;
141 case GNUNET_FS_QUEUE_PRIORITY_NORMAL:
142 break;
143 default:
144 GNUNET_break (0);
145 }
128 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time); 146 end_time = GNUNET_TIME_absolute_add (qe->start_time, run_time);
129 rst = GNUNET_TIME_absolute_get_remaining (end_time); 147 rst = GNUNET_TIME_absolute_get_remaining (end_time);
130 restart_at = GNUNET_TIME_relative_min (rst, restart_at); 148 restart_at = GNUNET_TIME_relative_min (rst, restart_at);
@@ -132,6 +150,18 @@ process_job_queue (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
132 continue; 150 continue;
133 stop_job (qe); 151 stop_job (qe);
134 } 152 }
153 /* finally, start some more tasks if we now have empty slots */
154 next = h->pending_head;
155 while (NULL != (qe = next))
156 {
157 next = qe->next;
158 if ((qe->blocks + h->active_blocks <= h->max_parallel_requests) &&
159 (h->active_downloads < h->max_parallel_downloads))
160 {
161 start_job (qe);
162 continue;
163 }
164 }
135 h->queue_job = 165 h->queue_job =
136 GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h); 166 GNUNET_SCHEDULER_add_delayed (restart_at, &process_job_queue, h);
137} 167}