summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElias Summermatter <elias.summermatter@seccom.ch>2021-05-05 14:00:00 +0200
committerElias Summermatter <elias.summermatter@seccom.ch>2021-05-05 14:00:00 +0200
commit01f628854116a1e3f5c4e344d71b09c527081638 (patch)
treee6e20fa803f962f0392bdf8475084f108c903564
parent04456797ea91414d636587099d167cd2347b9450 (diff)
Add new algo to determinate mode of operationsetu_perf
-rw-r--r--src/setu/gnunet-service-setu.c121
1 files changed, 118 insertions, 3 deletions
diff --git a/src/setu/gnunet-service-setu.c b/src/setu/gnunet-service-setu.c
index a47830086..d7143065f 100644
--- a/src/setu/gnunet-service-setu.c
+++ b/src/setu/gnunet-service-setu.c
@@ -78,12 +78,23 @@
*/
#define IBF_ALPHA 4
+/**
+ * Calculate min of two given Values
+ */
+
+#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
+
/**
* Minimal size of an ibf
*/
#define IBF_MIN_SIZE 36
+/**
+ * AVG RTT for differential sync when k=2 and Factor = 2
+ */
+#define DIFFERENTIAL_RTT_MEAN 3.65145
+
/**
* Current phase we are in for a union operation.
@@ -153,6 +164,14 @@ enum UnionOperationPhase
};
+enum MODE_OF_OPERATION
+{
+ DIFFERENTIAL_SYNC,
+ FULL_SYNC_LOCAL_SENDING_FIRST,
+ FULL_SYNC_REMOTE_SENDING_FIRST
+};
+
+
/**
* Information about an element element in the set. All elements are
* stored in a hash-table from their hash-code to their `struct
@@ -854,6 +873,91 @@ calculate_perf_rtt() {
return rtt;
}
+static uint8_t
+estimate_best_mode_of_operation(uint64_t avg_element_size,
+ uint64_t local_set_size,
+ uint64_t remote_set_size,
+ uint64_t est_set_diff_remote,
+ uint64_t est_set_diff_local,
+ uint64_t bandwith_latency_tradeoff,
+ uint64_t ibf_bucket_number_factor)
+{
+ /*
+ * Calculate bytes for full Sync
+ */
+
+ uint8_t SIZEOF_FULL_DONE_HEADER = 4;
+ uint8_t SIZEOF_DONE_HEADER = 4;
+ uint8_t RTT_MIN_FULL = 2;
+ uint8_t SIZEOF_REQUEST_FULL = 4;
+ uint16_t estimated_total_diff = (est_set_diff_remote + est_set_diff_local);
+
+ /* Estimate byte required if we send first */
+ uint64_t total_elements_to_send_local_send_first = local_set_size + est_set_diff_remote;
+
+ uint64_t total_bytes_full_local_send_first = (avg_element_size * total_elements_to_send_local_send_first) + \
+ (total_elements_to_send_local_send_first * sizeof(struct GNUNET_SETU_ElementMessage)) + \
+ (SIZEOF_FULL_DONE_HEADER * 2) + \
+ RTT_MIN_FULL * bandwith_latency_tradeoff;
+
+ /* Estimate bytes required if we request from remote peer */
+ uint64_t total_elements_to_send_remote_send_first = est_set_diff_local + remote_set_size;
+
+ uint64_t total_bytes_full_remote_send_first = (avg_element_size * total_elements_to_send_remote_send_first) + \
+ (total_elements_to_send_remote_send_first * sizeof(struct GNUNET_SETU_ElementMessage)) + \
+ (SIZEOF_FULL_DONE_HEADER * 2) + \
+ (RTT_MIN_FULL + 0.5) * bandwith_latency_tradeoff + \
+ SIZEOF_REQUEST_FULL;
+
+ /*
+ * Calculate bytes for differential Sync
+ */
+
+ /* Estimate bytes required by IBF transmission*/
+
+ double ibf_bucket_count = estimated_total_diff * ibf_bucket_number_factor;
+
+ if (ibf_bucket_count <= IBF_MIN_SIZE) {
+ ibf_bucket_count = IBF_MIN_SIZE;
+ }
+
+ uint64_t ibf_message_count = ceil((float) ibf_bucket_count / MAX_BUCKETS_PER_MESSAGE);
+
+ uint64_t estimated_counter_size = ceil(MIN(2 * log2l((float)local_set_size/ibf_bucket_count), log2l(local_set_size)));
+
+ float counter_bytes = (float) estimated_counter_size / 8;
+
+ uint64_t ibf_bytes = ceil((sizeof(struct IBFMessage) * ibf_message_count) * 1.2 + \
+ (ibf_bucket_count * sizeof(struct IBF_Key)) * 1.2 + \
+ (ibf_bucket_count * sizeof(struct IBF_KeyHash)) * 1.2 + \
+ (ibf_bucket_count * counter_bytes) * 1.2);
+
+ /* Estimate full byte count for differential sync */
+ uint64_t element_size=(avg_element_size + sizeof(struct GNUNET_SETU_ElementMessage)) * \
+ estimated_total_diff;
+ uint64_t done_size = SIZEOF_DONE_HEADER;
+ uint64_t inquery_size = (sizeof(struct IBF_Key) + sizeof(struct InquiryMessage)) * estimated_total_diff;
+ uint64_t demand_size = (sizeof(struct GNUNET_HashCode) + sizeof(struct GNUNET_MessageHeader)) * estimated_total_diff;
+ uint64_t offer_size = (sizeof(struct GNUNET_HashCode) + sizeof(struct GNUNET_MessageHeader)) * estimated_total_diff;
+
+ uint64_t total_bytes_diff = (element_size + done_size + inquery_size + demand_size + offer_size + ibf_bytes) + \
+ ( DIFFERENTIAL_RTT_MEAN * bandwith_latency_tradeoff );
+
+ uint64_t full_min = MIN(total_elements_to_send_local_send_first, total_elements_to_send_remote_send_first);
+
+ /* Decide between full and differential sync */
+ if (full_min < total_bytes_diff) {
+ /* Decide between sending all element first or receiving all elements */
+ if(total_bytes_full_remote_send_first > total_bytes_full_local_send_first) {
+ return FULL_SYNC_LOCAL_SENDING_FIRST;
+ } else {
+ return FULL_SYNC_REMOTE_SENDING_FIRST;
+ }
+ } else {
+ return DIFFERENTIAL_SYNC;
+ }
+}
+
/**
* Iterator over hash map entries, called to
@@ -1661,13 +1765,24 @@ handle_union_p2p_strata_estimator (void *cls,
int remote_elements_decoded = remote_se->strata[0]->remote_decoded_count;
int local_elements_decoded = remote_se->strata[0]->local_decoded_count;
- int total_decoded = remote_elements_decoded + local_elements_decoded;
- int diff_remote = ((float)remote_elements_decoded / (float)total_decoded) * diff;
- int diff_local = ((float)local_elements_decoded / (float)total_decoded) * diff;
+ uint64_t total_decoded = remote_elements_decoded + local_elements_decoded;
+ uint64_t diff_remote = ((float)remote_elements_decoded / (float)total_decoded) * diff;
+ uint64_t diff_local = ((float)local_elements_decoded / (float)total_decoded) * diff;
perf_rtt.se_diff_local = diff_local;
perf_rtt.se_diff_remote = diff_remote;
perf_rtt.se_diff = diff;
+
+ uint8_t mode_of_operation = estimate_best_mode_of_operation(32,
+ op->local_element_count,
+ op->remote_element_count,
+ diff_local,
+ diff_remote,
+ op->rtt_bandwidth_tradeoff,
+ op->ibf_bucket_number_factor);
+
+
+
/**
if (diff > 200)
diff = diff * 3 / 2;