Repository: kudu
Updated Branches:
  refs/heads/master 2c052fcb4 -> cf20c0e59


Reduce default RSA key length for tests

The default RSA key length for real servers is set to 2048 bits.
However, generating a 2048-bit RSA key is relatively expensive. Since we
do it on every server start, and our tests start thousands of servers,
this has a negative impact on test time.

This changes the default in ExternalMiniCluster and in our own tests to
512-bit keys, which appear to be about 16x faster to generate compared
to 2048-bit keys (based on 'perf stat -r50 openssl genrsa -out /tmp/r
<key length>').

I measured the improvement on registration-test from ~4000ms to ~1200ms
wall time on my laptop.

This also changes the way we override flags for tests to use the gflags
API instead of directly setting FLAGS_* variables. This cleans up some
workarounds we did previously and also allows us to set flags which
might not apply for all test cases (eg security flags aren't in util
tests).

Change-Id: I310ac762aff4fed891a0491b2c3249e0faa9375f
Reviewed-on: http://gerrit.cloudera.org:8080/5804
Tested-by: Kudu Jenkins
Reviewed-by: Dan Burkert <[email protected]>
Reviewed-by: Alexey Serbin <[email protected]>
Reviewed-by: Adar Dembo <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/kudu/repo
Commit: http://git-wip-us.apache.org/repos/asf/kudu/commit/ce04fe5f
Tree: http://git-wip-us.apache.org/repos/asf/kudu/tree/ce04fe5f
Diff: http://git-wip-us.apache.org/repos/asf/kudu/diff/ce04fe5f

Branch: refs/heads/master
Commit: ce04fe5f1cc67a268842ee7870a4f6ea6ae1fcc9
Parents: 2c052fc
Author: Todd Lipcon <[email protected]>
Authored: Thu Jan 26 14:02:24 2017 -0800
Committer: Todd Lipcon <[email protected]>
Committed: Fri Jan 27 00:07:38 2017 +0000

----------------------------------------------------------------------
 .../integration-tests/external_mini_cluster.cc  |  9 +++++++
 src/kudu/util/flag_tags-test.cc                 | 10 +-------
 src/kudu/util/flags-test.cc                     | 10 +-------
 src/kudu/util/test_util.cc                      | 25 +++++++++++++-------
 4 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/kudu/blob/ce04fe5f/src/kudu/integration-tests/external_mini_cluster.cc
----------------------------------------------------------------------
diff --git a/src/kudu/integration-tests/external_mini_cluster.cc 
b/src/kudu/integration-tests/external_mini_cluster.cc
index fb3f645..71e3fee 100644
--- a/src/kudu/integration-tests/external_mini_cluster.cc
+++ b/src/kudu/integration-tests/external_mini_cluster.cc
@@ -630,6 +630,11 @@ Status ExternalDaemon::StartProcess(const vector<string>& 
user_flags) {
   // rely on forcefully cutting power to a machine or equivalent.
   argv.push_back("--never_fsync");
 
+  // Generate smaller RSA keys -- generating a 512-bit key is >15x faster
+  // than generating the default 2048-bit key, and we don't care about
+  // strong encryption in tests.
+  argv.push_back("--server_rsa_key_length_bits=512");
+
   // Disable log redaction.
   argv.push_back("--log_redact_user_data=false");
 
@@ -1003,6 +1008,10 @@ ExternalMaster::~ExternalMaster() {
 
 Status ExternalMaster::Start() {
   vector<string> flags;
+
+  // Generate smaller RSA keys. See note above for server_rsa_key_length_bits.
+  flags.push_back("--master_ca_rsa_key_length_bits=512");
+
   flags.push_back("--fs_wal_dir=" + data_dir_);
   flags.push_back("--fs_data_dirs=" + data_dir_);
   flags.push_back("--rpc_bind_addresses=" + get_rpc_bind_address());

http://git-wip-us.apache.org/repos/asf/kudu/blob/ce04fe5f/src/kudu/util/flag_tags-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/flag_tags-test.cc b/src/kudu/util/flag_tags-test.cc
index 89b99a9..168afef 100644
--- a/src/kudu/util/flag_tags-test.cc
+++ b/src/kudu/util/flag_tags-test.cc
@@ -48,15 +48,7 @@ using std::unordered_set;
 
 namespace kudu {
 
-class FlagTagsTest : public KuduTest {
- public:
-  FlagTagsTest() {
-    // Set by KuduTest, and set back to the default value here as this test
-    // deals with unsafe and experimental flags.
-    FLAGS_never_fsync = false;
-    FLAGS_log_redact_user_data = true;
-  }
-};
+class FlagTagsTest : public KuduTest {};
 
 TEST_F(FlagTagsTest, TestTags) {
   unordered_set<string> tags;

http://git-wip-us.apache.org/repos/asf/kudu/blob/ce04fe5f/src/kudu/util/flags-test.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/flags-test.cc b/src/kudu/util/flags-test.cc
index ecf16d4..ab4d1d5 100644
--- a/src/kudu/util/flags-test.cc
+++ b/src/kudu/util/flags-test.cc
@@ -38,15 +38,7 @@ DECLARE_bool(log_redact_user_data);
 
 namespace kudu {
 
-class FlagsTest : public KuduTest {
- public:
-  FlagsTest() {
-    // Set by KuduTest, and set back to the default value here as this test
-    // deals with unsafe and experimental flags.
-    FLAGS_never_fsync = false;
-    FLAGS_log_redact_user_data = true;
-  }
-};
+class FlagsTest : public KuduTest {};
 
 TEST_F(FlagsTest, TestNonDefaultFlags) {
   // Memorize the default flags

http://git-wip-us.apache.org/repos/asf/kudu/blob/ce04fe5f/src/kudu/util/test_util.cc
----------------------------------------------------------------------
diff --git a/src/kudu/util/test_util.cc b/src/kudu/util/test_util.cc
index 3a08ef8..4228e85 100644
--- a/src/kudu/util/test_util.cc
+++ b/src/kudu/util/test_util.cc
@@ -16,6 +16,7 @@
 // under the License.
 #include "kudu/util/test_util.h"
 
+#include <map>
 #include <string>
 #include <vector>
 
@@ -33,9 +34,6 @@
 #include "kudu/util/random.h"
 #include "kudu/util/spinlock_profiling.h"
 
-DECLARE_bool(log_redact_user_data);
-DECLARE_bool(never_fsync);
-
 DEFINE_string(test_leave_files, "on_failure",
               "Whether to leave test files around after the test run. "
               " Valid values are 'always', 'on_failure', or 'never'");
@@ -67,12 +65,21 @@ bool g_is_gtest = true;
 KuduTest::KuduTest()
   : env_(Env::Default()),
     test_dir_(GetTestDataDirectory()) {
-  // Disabling fsync() speeds up tests dramatically, and it's safe to do as no
-  // tests rely on cutting power to a machine or equivalent.
-  FLAGS_never_fsync = true;
-
-  // Disable log redaction.
-  FLAGS_log_redact_user_data = false;
+  std::map<const char*, const char*> flags_for_tests = {
+    // Disabling fsync() speeds up tests dramatically, and it's safe to do as 
no
+    // tests rely on cutting power to a machine or equivalent.
+    {"never_fsync", "true"},
+    // Disable log redaction.
+    {"log_redact_user_data", "false"},
+    // Reduce default RSA key length for faster tests.
+    {"server_rsa_key_length_bits", "512"},
+    {"master_ca_rsa_key_length_bits", "512"}
+  };
+  for (const auto& e : flags_for_tests) {
+    // We don't check for errors here, because we have some default flags that
+    // only apply to certain tests.
+    google::SetCommandLineOptionWithMode(e.first, e.second, 
google::SET_FLAGS_DEFAULT);
+  }
 }
 
 KuduTest::~KuduTest() {

Reply via email to