diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-08-18 02:29:14 +0200 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-08-18 02:29:14 +0200 |
commit | adc9f7dc9978dd38d14c925e3e38d658f9300753 (patch) | |
tree | fe7add757b1221ec4e580cfdd52375017eb96593 /src | |
parent | f9c7588373cb3a047345e68377158965d8e8d08a (diff) | |
download | gnunet-adc9f7dc9978dd38d14c925e3e38d658f9300753.tar.gz gnunet-adc9f7dc9978dd38d14c925e3e38d658f9300753.zip |
URL benchmarking
Diffstat (limited to 'src')
-rw-r--r-- | src/curl/curl.c | 14 | ||||
-rw-r--r-- | src/util/benchmark.c | 67 | ||||
-rw-r--r-- | src/util/benchmark.h | 56 |
3 files changed, 136 insertions, 1 deletions
diff --git a/src/curl/curl.c b/src/curl/curl.c index 0d9342b60..9284d7b45 100644 --- a/src/curl/curl.c +++ b/src/curl/curl.c | |||
@@ -502,6 +502,20 @@ GNUNET_CURL_perform (struct GNUNET_CURL_Context *ctx) | |||
502 | j = download_get_result (&job->db, | 502 | j = download_get_result (&job->db, |
503 | job->easy_handle, | 503 | job->easy_handle, |
504 | &response_code); | 504 | &response_code); |
505 | #if ENABLE_BENCHMARK | ||
506 | { | ||
507 | char *url = NULL; | ||
508 | double total = 0; | ||
509 | struct UrlRequestData *urd; | ||
510 | CURLcode res; | ||
511 | res = curl_easy_getinfo (cmsg->easy_handle, CURLINFO_TOTAL_TIME, &total); | ||
512 | GNUNET_break (CURLE_OK == res); | ||
513 | curl_easy_getinfo (cmsg->easy_handle, CURLINFO_EFFECTIVE_URL, &url); | ||
514 | urd = get_url_benchmark_data (url); | ||
515 | urd->count++; | ||
516 | urd->time.rel_value_us += total * 1000 * 1000; | ||
517 | } | ||
518 | #endif | ||
505 | job->jcc (job->jcc_cls, | 519 | job->jcc (job->jcc_cls, |
506 | response_code, | 520 | response_code, |
507 | j); | 521 | j); |
diff --git a/src/util/benchmark.c b/src/util/benchmark.c index 4a0c9b7c8..421cafbef 100644 --- a/src/util/benchmark.c +++ b/src/util/benchmark.c | |||
@@ -71,6 +71,33 @@ write_benchmark_data (struct BenchmarkData *bd) | |||
71 | GNUNET_free (s); | 71 | GNUNET_free (s); |
72 | 72 | ||
73 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | 73 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); |
74 | |||
75 | GNUNET_asprintf (&s, "gnunet-benchmark-urls-%llu-%llu.txt", | ||
76 | (unsigned long long) pid, | ||
77 | (unsigned long long) tid); | ||
78 | |||
79 | fh = GNUNET_DISK_file_open (s, | ||
80 | (GNUNET_DISK_OPEN_WRITE | | ||
81 | GNUNET_DISK_OPEN_TRUNCATE | | ||
82 | GNUNET_DISK_OPEN_CREATE), | ||
83 | (GNUNET_DISK_PERM_USER_READ | | ||
84 | GNUNET_DISK_PERM_USER_WRITE)); | ||
85 | GNUNET_assert (NULL != fh); | ||
86 | GNUNET_free (s); | ||
87 | |||
88 | for (unsigned int i = 0; i < bd->urd_len; i++) | ||
89 | { | ||
90 | struct UrlRequestData *urd = &bd->urd[i]; | ||
91 | GNUNET_asprintf (&s, "url %s count %lld time_us %lld\n", | ||
92 | urd->request_url, | ||
93 | (unsigned long long) urd->count, | ||
94 | (unsigned long long) urd->time.rel_value_us); | ||
95 | GNUNET_assert (GNUNET_SYSERR != GNUNET_DISK_file_write_blocking (fh, s, strlen (s))); | ||
96 | GNUNET_free (s); | ||
97 | } | ||
98 | |||
99 | |||
100 | GNUNET_assert (GNUNET_OK == GNUNET_DISK_file_close (fh)); | ||
74 | } | 101 | } |
75 | 102 | ||
76 | 103 | ||
@@ -142,3 +169,43 @@ get_benchmark_data (void) | |||
142 | } | 169 | } |
143 | return bd; | 170 | return bd; |
144 | } | 171 | } |
172 | |||
173 | |||
174 | /** | ||
175 | * Get benchmark data for a URL. If the URL is too long, it's truncated | ||
176 | * before looking up the correspoding benchmark data. | ||
177 | * | ||
178 | * @param url url to get request data for | ||
179 | */ | ||
180 | struct UrlRequestData * | ||
181 | get_url_benchmark_data (char *url) | ||
182 | { | ||
183 | char trunc[MAX_BENCHMARK_URL_LEN]; | ||
184 | struct BenchmarkData *bd; | ||
185 | |||
186 | memcpy (trunc, url, MAX_BENCHMARK_URL_LEN); | ||
187 | trunc[MAX_BENCHMARK_URL_LEN - 1] = 0; | ||
188 | |||
189 | bd = get_benchmark_data (); | ||
190 | |||
191 | for (unsigned int i = 0; i < bd->urd_len; i++) | ||
192 | { | ||
193 | if (0 == strcmp (trunc, bd->urd[i].request_url)) | ||
194 | return &bd->urd[i]; | ||
195 | } | ||
196 | |||
197 | { | ||
198 | struct UrlRequestData urd = { 0 }; | ||
199 | |||
200 | memcpy (&urd.request_url, trunc, MAX_BENCHMARK_URL_LEN); | ||
201 | |||
202 | if (bd->urd_len == bd->urd_capacity) | ||
203 | { | ||
204 | bd->urd_capacity = 2 * (bd->urd_capacity + 1); | ||
205 | bd->urd = GNUNET_realloc (bd->urd, bd->urd_capacity * sizeof (struct UrlRequestData)); | ||
206 | } | ||
207 | |||
208 | bd->urd[bd->urd_len++] = urd; | ||
209 | return &bd->urd[bd->urd_len - 1]; | ||
210 | } | ||
211 | } | ||
diff --git a/src/util/benchmark.h b/src/util/benchmark.h index eec9c9c8a..ec00cb0d3 100644 --- a/src/util/benchmark.h +++ b/src/util/benchmark.h | |||
@@ -28,9 +28,48 @@ | |||
28 | #include "gnunet_time_lib.h" | 28 | #include "gnunet_time_lib.h" |
29 | 29 | ||
30 | /** | 30 | /** |
31 | * Maximum length of URLs considered for benchmarking. | ||
32 | * Shorter URLs are simply truncated. | ||
33 | */ | ||
34 | #define MAX_BENCHMARK_URL_LEN 128 | ||
35 | |||
36 | |||
37 | /** | ||
38 | * Struct for benchmark data for one URL. | ||
39 | */ | ||
40 | struct UrlRequestData | ||
41 | { | ||
42 | /** | ||
43 | * Request URL, truncated (but 0-terminated). | ||
44 | */ | ||
45 | char request_url[MAX_BENCHMARK_URL_LEN]; | ||
46 | |||
47 | /** | ||
48 | * How often was the URL requested? | ||
49 | */ | ||
50 | uint64_t count; | ||
51 | |||
52 | /** | ||
53 | * Total time spent requesting this URL. | ||
54 | */ | ||
55 | struct GNUNET_TIME_Relative time; | ||
56 | |||
57 | /** | ||
58 | * Slowest time to response. | ||
59 | */ | ||
60 | struct GNUNET_TIME_Relative time_max; | ||
61 | |||
62 | /** | ||
63 | * Fastest time to response. | ||
64 | */ | ||
65 | struct GNUNET_TIME_Relative time_min; | ||
66 | }; | ||
67 | |||
68 | /** | ||
31 | * Thread-local struct for benchmarking data. | 69 | * Thread-local struct for benchmarking data. |
32 | */ | 70 | */ |
33 | struct BenchmarkData { | 71 | struct BenchmarkData |
72 | { | ||
34 | /** | 73 | /** |
35 | * Number of eddsa_sign operations. | 74 | * Number of eddsa_sign operations. |
36 | */ | 75 | */ |
@@ -40,6 +79,12 @@ struct BenchmarkData { | |||
40 | * Time spent in eddsa_sign. | 79 | * Time spent in eddsa_sign. |
41 | */ | 80 | */ |
42 | struct GNUNET_TIME_Relative eddsa_sign_time; | 81 | struct GNUNET_TIME_Relative eddsa_sign_time; |
82 | |||
83 | struct UrlRequestData *urd; | ||
84 | |||
85 | unsigned int urd_len; | ||
86 | |||
87 | unsigned int urd_capacity; | ||
43 | }; | 88 | }; |
44 | 89 | ||
45 | 90 | ||
@@ -52,4 +97,13 @@ struct BenchmarkData { | |||
52 | struct BenchmarkData * | 97 | struct BenchmarkData * |
53 | get_benchmark_data (void); | 98 | get_benchmark_data (void); |
54 | 99 | ||
100 | /** | ||
101 | * Get benchmark data for a URL. If the URL is too long, it's truncated | ||
102 | * before looking up the correspoding benchmark data. | ||
103 | * | ||
104 | * @param url url to get request data for | ||
105 | */ | ||
106 | struct UrlRequestData * | ||
107 | get_url_benchmark_data (char *url); | ||
108 | |||
55 | #endif /* BENCHMARK_H_ */ | 109 | #endif /* BENCHMARK_H_ */ |