summaryrefslogtreecommitdiff
path: root/src/feature
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2021-02-22 15:39:30 -0500
committerNick Mathewson <nickm@torproject.org>2021-02-22 15:39:30 -0500
commit890780054975e0c5eb95b097deb6fac53640f66d (patch)
treea4593a5168d01b3ce3820e21cccd31334a3918f6 /src/feature
parent6e3a7c410f2c0cfd2f705862cc4d32acd0a88096 (diff)
parentd98c77b78e9ce945a7a0de151d5f5cf44061edd5 (diff)
downloadtor-890780054975e0c5eb95b097deb6fac53640f66d.tar.gz
tor-890780054975e0c5eb95b097deb6fac53640f66d.zip
Merge remote-tracking branch 'tor-gitlab/mr/319'
Diffstat (limited to 'src/feature')
-rw-r--r--src/feature/dircache/dircache.c37
-rw-r--r--src/feature/dircache/dircache.h2
2 files changed, 21 insertions, 18 deletions
diff --git a/src/feature/dircache/dircache.c b/src/feature/dircache/dircache.c
index 013fd1f9ae..ae9ff55d71 100644
--- a/src/feature/dircache/dircache.c
+++ b/src/feature/dircache/dircache.c
@@ -295,19 +295,22 @@ client_likes_consensus(const struct consensus_cache_entry_t *ent,
/** Return the compression level we should use for sending a compressed
* response of size <b>n_bytes</b>. */
STATIC compression_level_t
-choose_compression_level(ssize_t n_bytes)
+choose_compression_level(void)
{
- if (! have_been_under_memory_pressure()) {
- return HIGH_COMPRESSION; /* we have plenty of RAM. */
- } else if (n_bytes < 0) {
- return HIGH_COMPRESSION; /* unknown; might be big. */
- } else if (n_bytes < 1024) {
- return LOW_COMPRESSION;
- } else if (n_bytes < 2048) {
- return MEDIUM_COMPRESSION;
- } else {
- return HIGH_COMPRESSION;
- }
+ /* This is the compression level choice for a stream.
+ *
+ * We always return LOW because this compression is done in the main thread
+ * thus we save CPU time as much as possible, and it is also done more than
+ * background compression for document we serve pre-compressed.
+ *
+ * GZip highest compression level (9) gives us a ratio of 49.72%
+ * Zstd lowest compression level (1) gives us a ratio of 47.38%
+ *
+ * Thus, as the network moves more and more to use Zstd when requesting
+ * directory documents that are not pre-cached, even at the
+ * lowest level, we still gain over GZip and thus help with load and CPU
+ * time on the network. */
+ return LOW_COMPRESSION;
}
/** Information passed to handle a GET request. */
@@ -1074,7 +1077,7 @@ handle_get_status_vote(dir_connection_t *conn, const get_handler_args_t *args)
if (smartlist_len(items)) {
if (compress_method != NO_METHOD) {
conn->compress_state = tor_compress_new(1, compress_method,
- choose_compression_level(estimated_len));
+ choose_compression_level());
}
SMARTLIST_FOREACH(items, const char *, c,
@@ -1137,7 +1140,7 @@ handle_get_microdesc(dir_connection_t *conn, const get_handler_args_t *args)
if (compress_method != NO_METHOD)
conn->compress_state = tor_compress_new(1, compress_method,
- choose_compression_level(size_guess));
+ choose_compression_level());
const int initial_flush_result = connection_dirserv_flushed_some(conn);
tor_assert_nonfatal(initial_flush_result == 0);
@@ -1232,7 +1235,7 @@ handle_get_descriptor(dir_connection_t *conn, const get_handler_args_t *args)
write_http_response_header(conn, -1, compress_method, cache_lifetime);
if (compress_method != NO_METHOD)
conn->compress_state = tor_compress_new(1, compress_method,
- choose_compression_level(size_guess));
+ choose_compression_level());
clear_spool = 0;
/* Prime the connection with some data. */
int initial_flush_result = connection_dirserv_flushed_some(conn);
@@ -1328,7 +1331,7 @@ handle_get_keys(dir_connection_t *conn, const get_handler_args_t *args)
60*60);
if (compress_method != NO_METHOD) {
conn->compress_state = tor_compress_new(1, compress_method,
- choose_compression_level(len));
+ choose_compression_level());
}
SMARTLIST_FOREACH(certs, authority_cert_t *, c,
@@ -1442,7 +1445,7 @@ handle_get_next_bandwidth(dir_connection_t *conn,
compress_method, BANDWIDTH_CACHE_LIFETIME);
if (compress_method != NO_METHOD) {
conn->compress_state = tor_compress_new(1, compress_method,
- choose_compression_level(len/2));
+ choose_compression_level());
log_debug(LD_DIR, "Compressing bandwidth file.");
} else {
log_debug(LD_DIR, "Not compressing bandwidth file.");
diff --git a/src/feature/dircache/dircache.h b/src/feature/dircache/dircache.h
index d6392e2d42..8e0945125d 100644
--- a/src/feature/dircache/dircache.h
+++ b/src/feature/dircache/dircache.h
@@ -26,7 +26,7 @@ MOCK_DECL(STATIC int, directory_handle_command_post,(dir_connection_t *conn,
STATIC int handle_post_hs_descriptor(const char *url, const char *body);
enum compression_level_t;
-STATIC enum compression_level_t choose_compression_level(ssize_t n_bytes);
+STATIC enum compression_level_t choose_compression_level(void);
struct get_handler_args_t;
STATIC int handle_get_hs_descriptor_v3(dir_connection_t *conn,