aboutsummaryrefslogtreecommitdiff
path: root/src/fs/gnunet-service-fs_pe.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-25 23:47:39 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-25 23:47:39 +0000
commit7c55f94e78c72d3b78a5c6007e3658ae30e1f64b (patch)
tree77cb53d80cbb79053a68c71a270586e6e0dcb1ef /src/fs/gnunet-service-fs_pe.c
parent124f3e77a5e022f5f7ab49df49023d0080bcbbb4 (diff)
downloadgnunet-7c55f94e78c72d3b78a5c6007e3658ae30e1f64b.tar.gz
gnunet-7c55f94e78c72d3b78a5c6007e3658ae30e1f64b.zip
-use hash in prd query to reduce memory consumption of CP request_map
Diffstat (limited to 'src/fs/gnunet-service-fs_pe.c')
-rw-r--r--src/fs/gnunet-service-fs_pe.c69
1 files changed, 45 insertions, 24 deletions
diff --git a/src/fs/gnunet-service-fs_pe.c b/src/fs/gnunet-service-fs_pe.c
index ede109c2d..9743d1cb2 100644
--- a/src/fs/gnunet-service-fs_pe.c
+++ b/src/fs/gnunet-service-fs_pe.c
@@ -59,7 +59,7 @@ struct PeerPlan;
59 * to a given plan entry.) 59 * to a given plan entry.)
60 * 60 *
61 * Similarly head and tail of the "PR" MDLL are stored 61 * Similarly head and tail of the "PR" MDLL are stored
62 * with the 'struct GSF_PendingRequest'. (We need 62 * with the `struct GSF_PendingRequest`. (We need
63 * to be able to lookup all plan entries corresponding 63 * to be able to lookup all plan entries corresponding
64 * to a given pending request.) 64 * to a given pending request.)
65 */ 65 */
@@ -87,12 +87,14 @@ struct GSF_PendingRequestPlanBijection
87 struct GSF_PendingRequestPlanBijection *prev_PE; 87 struct GSF_PendingRequestPlanBijection *prev_PE;
88 88
89 /** 89 /**
90 * Associated request plan. 90 * Associated request plan (tells us one of the peers that
91 * we plan to forward the request to).
91 */ 92 */
92 struct GSF_RequestPlan *rp; 93 struct GSF_RequestPlan *rp;
93 94
94 /** 95 /**
95 * Associated pending request. 96 * Associated pending request (identifies request details
97 * and one of the origins of the request).
96 */ 98 */
97 struct GSF_PendingRequest *pr; 99 struct GSF_PendingRequest *pr;
98 100
@@ -101,8 +103,8 @@ struct GSF_PendingRequestPlanBijection
101 103
102/** 104/**
103 * Information we keep per request per peer. This is a doubly-linked 105 * Information we keep per request per peer. This is a doubly-linked
104 * list (with head and tail in the 'struct GSF_PendingRequestData') 106 * list (with head and tail in the `struct GSF_PendingRequestData`)
105 * with one entry in each heap of each 'struct PeerPlan'. Each 107 * with one entry in each heap of each `struct PeerPlan`. Each
106 * entry tracks information relevant for this request and this peer. 108 * entry tracks information relevant for this request and this peer.
107 */ 109 */
108struct GSF_RequestPlan 110struct GSF_RequestPlan
@@ -129,7 +131,9 @@ struct GSF_RequestPlan
129 struct PeerPlan *pp; 131 struct PeerPlan *pp;
130 132
131 /** 133 /**
132 * Head of list of associated pending requests. 134 * Head of list of associated pending requests. This tells us
135 * which incoming requests from other peers this plan entry
136 * corresponds to.
133 */ 137 */
134 struct GSF_PendingRequestPlanBijection *pe_head; 138 struct GSF_PendingRequestPlanBijection *pe_head;
135 139
@@ -167,19 +171,20 @@ struct GSF_RequestPlan
167struct PeerPlan 171struct PeerPlan
168{ 172{
169 /** 173 /**
170 * Heap with pending queries (struct GSF_RequestPlan), higher weights mean higher priority. 174 * Heap with pending queries (`struct GSF_RequestPlan`), higher weights mean higher priority.
171 */ 175 */
172 struct GNUNET_CONTAINER_Heap *priority_heap; 176 struct GNUNET_CONTAINER_Heap *priority_heap;
173 177
174 /** 178 /**
175 * Heap with pending queries (struct GSF_RequestPlan), by transmission time, lowest first. 179 * Heap with pending queries (`struct GSF_RequestPlan`), by transmission time, lowest first.
176 */ 180 */
177 struct GNUNET_CONTAINER_Heap *delay_heap; 181 struct GNUNET_CONTAINER_Heap *delay_heap;
178 182
179 /** 183 /**
180 * Map of queries to plan entries. All entries in the priority_heap or delay_heap 184 * Map of queries to plan entries. All entries in the @e priority_heap
181 * should be in the plan map. Note that it IS possible for the plan map to have 185 * or @e delay_heap should be in the @e plan_map. Note that it is
182 * multiple entries for the same query. 186 * possible for the @e plan_map to have multiple entries for the same
187 * query.
183 */ 188 */
184 struct GNUNET_CONTAINER_MultiHashMap *plan_map; 189 struct GNUNET_CONTAINER_MultiHashMap *plan_map;
185 190
@@ -196,7 +201,7 @@ struct PeerPlan
196 /** 201 /**
197 * Current task for executing the plan. 202 * Current task for executing the plan.
198 */ 203 */
199 struct GNUNET_SCHEDULER_Task * task; 204 struct GNUNET_SCHEDULER_Task *task;
200}; 205};
201 206
202 207
@@ -222,7 +227,7 @@ static unsigned long long plan_count;
222 * requests for the same key and we just return _one_ of them; this 227 * requests for the same key and we just return _one_ of them; this
223 * particular one might complete while another one might still be 228 * particular one might complete while another one might still be
224 * active, hence the lifetime of the returned hash code is NOT 229 * active, hence the lifetime of the returned hash code is NOT
225 * necessarily identical to that of the 'struct GSF_RequestPlan' 230 * necessarily identical to that of the `struct GSF_RequestPlan`
226 * given. 231 * given.
227 * 232 *
228 * @param rp a request plan 233 * @param rp a request plan
@@ -253,7 +258,8 @@ schedule_peer_transmission (void *cls,
253 * @param rp request to plan 258 * @param rp request to plan
254 */ 259 */
255static void 260static void
256plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp) 261plan (struct PeerPlan *pp,
262 struct GSF_RequestPlan *rp)
257{ 263{
258#define N ((double)128.0) 264#define N ((double)128.0)
259 /** 265 /**
@@ -366,8 +372,7 @@ get_latest (const struct GSF_RequestPlan *rp)
366 for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE) 372 for (bi = bi->next_PE; NULL != bi; bi = bi->next_PE)
367 { 373 {
368 prd = GSF_pending_request_get_data_ (bi->pr); 374 prd = GSF_pending_request_get_data_ (bi->pr);
369 if (prd->ttl.abs_value_us > 375 if (prd->ttl.abs_value_us > rprd->ttl.abs_value_us)
370 rprd->ttl.abs_value_us)
371 { 376 {
372 ret = bi->pr; 377 ret = bi->pr;
373 rprd = prd; 378 rprd = prd;
@@ -383,10 +388,12 @@ get_latest (const struct GSF_RequestPlan *rp)
383 * @param cls closure 388 * @param cls closure
384 * @param buf_size number of bytes available in @a buf 389 * @param buf_size number of bytes available in @a buf
385 * @param buf where to copy the message, NULL on error (peer disconnect) 390 * @param buf where to copy the message, NULL on error (peer disconnect)
386 * @return number of bytes copied to 'buf', can be 0 (without indicating an error) 391 * @return number of bytes copied to @a buf, can be 0 (without indicating an error)
387 */ 392 */
388static size_t 393static size_t
389transmit_message_callback (void *cls, size_t buf_size, void *buf) 394transmit_message_callback (void *cls,
395 size_t buf_size,
396 void *buf)
390{ 397{
391 struct PeerPlan *pp = cls; 398 struct PeerPlan *pp = cls;
392 struct GSF_RequestPlan *rp; 399 struct GSF_RequestPlan *rp;
@@ -414,7 +421,9 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
414 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp); 421 pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
415 return 0; 422 return 0;
416 } 423 }
417 msize = GSF_pending_request_get_message_ (get_latest (rp), buf_size, buf); 424 msize = GSF_pending_request_get_message_ (get_latest (rp),
425 buf_size,
426 buf);
418 if (msize > buf_size) 427 if (msize > buf_size)
419 { 428 {
420 if (NULL != pp->task) 429 if (NULL != pp->task)
@@ -476,7 +485,8 @@ schedule_peer_transmission (void *cls,
476 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap); 485 rp = GNUNET_CONTAINER_heap_peek (pp->delay_heap);
477 if (NULL == rp) 486 if (NULL == rp)
478 { 487 {
479 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No active requests for plan %p.\n", 488 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
489 "No active requests for plan %p.\n",
480 pp); 490 pp);
481 return; /* both queues empty */ 491 return; /* both queues empty */
482 } 492 }
@@ -486,11 +496,14 @@ schedule_peer_transmission (void *cls,
486 GNUNET_STRINGS_relative_time_to_string (delay, 496 GNUNET_STRINGS_relative_time_to_string (delay,
487 GNUNET_YES), 497 GNUNET_YES),
488 pp); 498 pp);
489 GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# delay heap timeout (ms)"), 499 GNUNET_STATISTICS_set (GSF_stats,
500 gettext_noop ("# delay heap timeout (ms)"),
490 delay.rel_value_us / 1000LL, GNUNET_NO); 501 delay.rel_value_us / 1000LL, GNUNET_NO);
491 502
492 pp->task = 503 pp->task =
493 GNUNET_SCHEDULER_add_delayed (delay, &schedule_peer_transmission, pp); 504 GNUNET_SCHEDULER_add_delayed (delay,
505 &schedule_peer_transmission,
506 pp);
494 return; 507 return;
495 } 508 }
496#if INSANE_STATISTICS 509#if INSANE_STATISTICS
@@ -503,8 +516,10 @@ schedule_peer_transmission (void *cls,
503 GNUNET_assert (NULL != rp); 516 GNUNET_assert (NULL != rp);
504 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL); 517 msize = GSF_pending_request_get_message_ (get_latest (rp), 0, NULL);
505 pp->pth = 518 pp->pth =
506 GSF_peer_transmit_ (pp->cp, GNUNET_YES, rp->priority, 519 GSF_peer_transmit_ (pp->cp, GNUNET_YES,
507 GNUNET_TIME_UNIT_FOREVER_REL, msize, 520 rp->priority,
521 GNUNET_TIME_UNIT_FOREVER_REL,
522 msize,
508 &transmit_message_callback, pp); 523 &transmit_message_callback, pp);
509 GNUNET_assert (NULL != pp->pth); 524 GNUNET_assert (NULL != pp->pth);
510} 525}
@@ -516,8 +531,14 @@ schedule_peer_transmission (void *cls,
516struct MergeContext 531struct MergeContext
517{ 532{
518 533
534 /**
535 * Request we are trying to merge.
536 */
519 struct GSF_PendingRequest *pr; 537 struct GSF_PendingRequest *pr;
520 538
539 /**
540 * Set to #GNUNET_YES if we succeeded to merge.
541 */
521 int merged; 542 int merged;
522 543
523}; 544};