aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-05-12 16:14:24 +0200
committerChristian Grothoff <christian@grothoff.org>2019-05-12 16:14:24 +0200
commitede8f88d298e25130347fcd97cac6c58b1a4caa1 (patch)
tree166d08fc93157d478a7bf1bedbcfa69c7fce73cc
parent373d4a33f361b18de61c319287950d4d349ed48b (diff)
downloadgnunet-ede8f88d298e25130347fcd97cac6c58b1a4caa1.tar.gz
gnunet-ede8f88d298e25130347fcd97cac6c58b1a4caa1.zip
implement message selection heuristic
-rw-r--r--src/transport/gnunet-service-tng.c44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index 4e8947237..727ef7f9c 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -24,7 +24,6 @@
24 * 24 *
25 * TODO: 25 * TODO:
26 * Implement next: 26 * Implement next:
27 * - FIXME-NEXT: logic to decide which pm to pick for a given queue (sorting!)
28 * - FIXME-FC: realize transport-to-transport flow control (needed in case 27 * - FIXME-FC: realize transport-to-transport flow control (needed in case
29 * communicators do not offer flow control). Note that we may not 28 * communicators do not offer flow control). Note that we may not
30 * want to simply delay the ACKs as that may cause unnecessary 29 * want to simply delay the ACKs as that may cause unnecessary
@@ -7817,10 +7816,45 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
7817 message would beat it! */ 7816 message would beat it! */
7818 if (NULL != sc->best) 7817 if (NULL != sc->best)
7819 { 7818 {
7820 /* FIXME-NEXT: CHECK if pos fits queue BETTER than pm, if not: 7819 /* CHECK if pos fits queue BETTER (=smaller) than pm, if not: continue;
7821 continue; */ 7820 OPTIMIZE-ME: This is a heuristic, which so far has NOT been
7822 /* NOTE: use 'overhead' to estimate need for fragmentation, 7821 experimentally validated. There may be some huge potential for
7823 prefer it if MTU is sufficient and close! */ 7822 improvement here. Also, we right now only compare how well the
7823 given message fits _this_ queue, and do not consider how well other
7824 queues might suit the message. Taking other queues into consideration
7825 may further improve the result, but could also be expensive
7826 in terms of CPU time. */
7827 long long sc_score = sc->frag * 40 + sc->relb * 20 + sc->real_overhead;
7828 long long pm_score = frag * 40 + relb * 20 + real_overhead;
7829 long long time_delta =
7830 (sc->best->next_attempt.abs_value_us - pos->next_attempt.abs_value_us) /
7831 1000LL;
7832
7833 /* "time_delta" considers which message has been 'ready' for transmission
7834 for longer, if a message has a preference for low latency, increase
7835 the weight of the time_delta by 10x if it is favorable for that message */
7836 if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
7837 (0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)))
7838 time_delta *= 10; /* increase weight (always, both are low latency) */
7839 else if ((0 != (pos->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
7840 (time_delta > 0))
7841 time_delta *=
7842 10; /* increase weight, favors 'pos', which is low latency */
7843 else if ((0 != (sc->best->prefs & GNUNET_MQ_PREF_LOW_LATENCY)) &&
7844 (time_delta < 0))
7845 time_delta *=
7846 10; /* increase weight, favors 'sc->best', which is low latency */
7847 if (0 != queue->mtu)
7848 {
7849 /* Grant bonus if we are bellow MTU, larger bonus the closer we will
7850 be to the MTU */
7851 if (queue->mtu > sc->real_overhead + sc->best->bytes_msg)
7852 sc_score -= queue->mtu - (sc->real_overhead + sc->best->bytes_msg);
7853 if (queue->mtu > real_overhead + pos->bytes_msg)
7854 pm_score -= queue->mtu - (real_overhead + pos->bytes_msg);
7855 }
7856 if (sc_score + time_delta > pm_score)
7857 continue; /* sc_score larger, keep sc->best */
7824 } 7858 }
7825 sc->best = pos; 7859 sc->best = pos;
7826 sc->dvh = dvh; 7860 sc->dvh = dvh;