diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-02-24 14:31:51 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-02-24 14:31:51 +0100 |
commit | 475fbe3cbea50b1e7bb6c5f02d80a0e1d2c63ced (patch) | |
tree | 7be42c126134785b979b670d7683e4b9160b5ceb /src/core | |
parent | 1b056f8811c06936144c611f8dbf26dc6a827b9e (diff) | |
download | gnunet-475fbe3cbea50b1e7bb6c5f02d80a0e1d2c63ced.tar.gz gnunet-475fbe3cbea50b1e7bb6c5f02d80a0e1d2c63ced.zip |
improve traffic drop heuristic
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/gnunet-service-core.c | 36 |
1 files changed, 33 insertions, 3 deletions
diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index bf941e7d8..31b91f12f 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c | |||
@@ -34,9 +34,17 @@ | |||
34 | /** | 34 | /** |
35 | * How many messages do we queue up at most for any client? This can | 35 | * How many messages do we queue up at most for any client? This can |
36 | * cause messages to be dropped if clients do not process them fast | 36 | * cause messages to be dropped if clients do not process them fast |
37 | * enough! | 37 | * enough! Note that this is a soft limit; we try |
38 | * to keep a few larger messages above the limit. | ||
38 | */ | 39 | */ |
39 | #define MAX_QUEUE 128 | 40 | #define SOFT_MAX_QUEUE 128 |
41 | |||
42 | /** | ||
43 | * How many messages do we queue up at most for any client? This can | ||
44 | * cause messages to be dropped if clients do not process them fast | ||
45 | * enough! Note that this is the hard limit. | ||
46 | */ | ||
47 | #define HARD_MAX_QUEUE 256 | ||
40 | 48 | ||
41 | 49 | ||
42 | /** | 50 | /** |
@@ -819,6 +827,7 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
819 | struct GNUNET_MQ_Envelope *env; | 827 | struct GNUNET_MQ_Envelope *env; |
820 | struct NotifyTrafficMessage *ntm; | 828 | struct NotifyTrafficMessage *ntm; |
821 | uint16_t mtype; | 829 | uint16_t mtype; |
830 | unsigned int qlen; | ||
822 | int tm; | 831 | int tm; |
823 | 832 | ||
824 | tm = type_match (ntohs (msg->type), | 833 | tm = type_match (ntohs (msg->type), |
@@ -834,7 +843,28 @@ GSC_CLIENTS_deliver_message (const struct GNUNET_PeerIdentity *sender, | |||
834 | if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && | 843 | if ( (0 != (options & GNUNET_CORE_OPTION_SEND_HDR_OUTBOUND)) && |
835 | (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) ) | 844 | (0 != (c->options & GNUNET_CORE_OPTION_SEND_FULL_OUTBOUND)) ) |
836 | continue; | 845 | continue; |
837 | if (MAX_QUEUE < GNUNET_MQ_get_length (c->mq)) | 846 | |
847 | /* Drop messages if: | ||
848 | 1) We are above the hard limit, or | ||
849 | 2) We are above the soft limit, and a coin toss limited | ||
850 | to the message size (giving larger messages a | ||
851 | proportionally higher chance of being queued) falls | ||
852 | below the threshold. The threshold is based on where | ||
853 | we are between the soft and the hard limit, scaled | ||
854 | to match the range of message sizes we usually encounter | ||
855 | (i.e. up to 32k); so a 64k message has a 50% chance of | ||
856 | being kept if we are just barely below the hard max, | ||
857 | and a 99% chance of being kept if we are at the soft max. | ||
858 | The reason is to make it more likely to drop control traffic | ||
859 | (ACK, queries) which may be cummulative or highly redundant, | ||
860 | and cheap to drop than data traffic. */ | ||
861 | qlen = GNUNET_MQ_get_length (c->mq); | ||
862 | if ( (qlen >= HARD_MAX_QUEUE) || | ||
863 | ( (qlen > SOFT_MAX_QUEUE) && | ||
864 | ( (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
865 | ntohs (msg->size)) ) < | ||
866 | (qlen - SOFT_MAX_QUEUE) * 0x8000 / | ||
867 | (HARD_MAX_QUEUE - SOFT_MAX_QUEUE) ) ) ) | ||
838 | { | 868 | { |
839 | char buf[1024]; | 869 | char buf[1024]; |
840 | 870 | ||