Просмотр исходного кода

Optimize serialization of Vec<u8> and boost throughput to 150%.

Jing Yang 3 лет назад
Родитель
Сommit
b9a9591bec
4 измененных файлов с 16 добавлено и 1 удалено
  1. 1 0
      Cargo.toml
  2. 1 0
      src/log_array.rs
  3. 1 1
      src/messages.rs
  4. 13 0
      tests/snapshot_tests.rs

+ 1 - 0
Cargo.toml

@@ -25,6 +25,7 @@ parking_lot = "0.12"
 rand = "0.8"
 serde = "1.0"
 serde_derive = "1.0"
+serde_bytes = "0.11.9"
 tokio = { version = "1.7", features = ["net", "rt-multi-thread", "sync", "time", "parking_lot"] }
 test_utils = { path = "test_utils", optional = true }
 

+ 1 - 0
src/log_array.rs

@@ -46,6 +46,7 @@ pub struct LogEntry<Command> {
 #[derive(Clone, Serialize, Deserialize)]
 pub(crate) struct LogArray<C> {
     inner: Vec<LogEntry<C>>,
+    #[serde(with = "serde_bytes")]
     snapshot: Vec<u8>,
 }
 

+ 1 - 1
src/messages.rs

@@ -42,7 +42,7 @@ pub struct InstallSnapshotArgs {
     pub(crate) leader_id: Peer,
     pub(crate) last_included_index: Index,
     pub(crate) last_included_term: Term,
-    // TODO(ditsing): Serde cannot handle Vec<u8> as efficient as expected.
+    #[serde(with = "serde_bytes")]
     pub(crate) data: Vec<u8>,
     pub(crate) offset: usize,
     pub(crate) done: bool,

+ 13 - 0
tests/snapshot_tests.rs

@@ -167,3 +167,16 @@ fn linearizability() {
         test_linearizability: true,
     });
 }
+
+#[ignore = "Large test with too many threads"]
+#[test]
+fn snapshot_throughput() {
+    init_test_log!();
+    generic_test(GenericTestParams {
+        // To boost client count to 48 we need more network threads in labrpc.
+        clients: 32,
+        crash: true,
+        maxraftstate: Some(10000),
+        ..Default::default()
+    })
+}