6.5840 Lab 2: Key/Value Server

· Technology

Lab 2: Key/Value Server

Code MR

# Testing Distributed Systems for Linearizability

task1

不需要考虑执行失败的情况

task2

linearizable. notes

考虑 rpc 调用失败,多次调用,多个 client 只需要确保一定会调用成功就行。

Client:,需要一个 id 标识,然后一个 client 还维护 sequence 来标识多次操作调用。

这里 id 生成使用了随机数(伪随机)的,场景简单,正确应该使用分布式 ID 生成算法如 UUID,Snowflake,原子自增。

Server: 记录每个 client 的最后一次执行结果,seq/clientID/result

如果直接多加个 map[client_id]info,让 get/put/append 都缓存,下面两个测试 memory 过不去。

memory use many put clients
memory use many get client

其实 GET 和 PUT 本身就是幂等的,不需要缓存结果。

[ultraman:...orkspace/MIT6.824/src/kvsrv]$ go test                                                                                           (lab2-key/value-server✱)
Test: one client ...
  ... Passed -- t  3.9 nrpc 33569 ops 33569
Test: many clients ...
  ... Passed -- t  5.0 nrpc 121387 ops 121387
Test: unreliable net, many clients ...
  ... Passed -- t  3.4 nrpc  1116 ops  910
Test: concurrent append to same key, unreliable ...
  ... Passed -- t  0.3 nrpc    64 ops   52
Test: memory use get ...
  ... Passed -- t  0.4 nrpc     5 ops    0
Test: memory use put ...
  ... Passed -- t  0.2 nrpc     2 ops    0
Test: memory use append ...
  ... Passed -- t  0.3 nrpc     2 ops    0
Test: memory use many put clients ...
  ... Passed -- t 10.1 nrpc 100000 ops    0
Test: memory use many get client ...
  ... Passed -- t 11.1 nrpc 100001 ops    0
Test: memory use many appends ...
2024/08/27 14:36:46 m0 393056 m1 2397752
  ... Passed -- t  1.7 nrpc  1000 ops    0
PASS
ok      6.5840/kvsrv    37.664s
 
 
[ultraman:...orkspace/MIT6.824/src/kvsrv]$ go test --race                                                                                    (lab2-key/value-server✱)
Test: one client ...
  ... Passed -- t  3.2 nrpc 10359 ops 10359
Test: many clients ...
  ... Passed -- t  3.4 nrpc 39739 ops 39739
Test: unreliable net, many clients ...
  ... Passed -- t  3.3 nrpc  1114 ops  898
Test: concurrent append to same key, unreliable ...
  ... Passed -- t  0.3 nrpc    66 ops   52
Test: memory use get ...
  ... Passed -- t  5.7 nrpc     4 ops    0
Test: memory use put ...
  ... Passed -- t  5.6 nrpc     2 ops    0
Test: memory use append ...
  ... Passed -- t 10.4 nrpc     2 ops    0
Test: memory use many put clients ...
  ... Passed -- t 30.7 nrpc 100000 ops    0
Test: memory use many get client ...
 
  ... Passed -- t 30.7 nrpc 100001 ops    0
Test: memory use many appends ...
2024/08/27 14:40:48 m0 344352 m1 2347736
  ... Passed -- t  6.6 nrpc  1000 ops    0
PASS
ok      6.5840/kvsrv    102.805s

Comments (0)

    Send comment

    Markdown supported. Please keep comments clean.