update
This commit is contained in:
@@ -110,11 +110,11 @@ check_lab5b() {
|
||||
check_cmd go test -c
|
||||
# also check other labs/parts
|
||||
cd "$tmpdir"
|
||||
check_lab4a
|
||||
check_lab5a
|
||||
cd "$tmpdir"
|
||||
check_lab4
|
||||
cd "$tmpdir"
|
||||
check_lab3
|
||||
cd "$tmpdir"
|
||||
check_lab2
|
||||
}
|
||||
|
||||
check_cmd() {
|
||||
|
||||
@@ -29,7 +29,7 @@ func MakeClerk(servers []*labrpc.ClientEnd) *Clerk {
|
||||
// keeps trying forever in the face of all other errors.
|
||||
//
|
||||
// you can send an RPC with code like this:
|
||||
// ok := ck.servers[i].Call("KVServer.Get", &args, &reply)
|
||||
// ok := ck.servers[i].Call("KVServer."+op, &args, &reply)
|
||||
//
|
||||
// the types of args and reply (including whether they are pointers)
|
||||
// must match the declared types of the RPC handler function's
|
||||
@@ -43,7 +43,7 @@ func (ck *Clerk) Get(key string) string {
|
||||
// shared by Put and Append.
|
||||
//
|
||||
// you can send an RPC with code like this:
|
||||
// ok := ck.servers[i].Call("KVServer."+op, &args, &reply)
|
||||
// ok := ck.servers[i].Call("KVServer.PutAppend", &args, &reply)
|
||||
//
|
||||
// the types of args and reply (including whether they are pointers)
|
||||
// must match the declared types of the RPC handler function's
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package kvraft
|
||||
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
|
||||
"6.5840/labgob"
|
||||
"6.5840/labrpc"
|
||||
"6.5840/raft"
|
||||
"log"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
)
|
||||
|
||||
const Debug = false
|
||||
@@ -19,6 +18,7 @@ func DPrintf(format string, a ...interface{}) (n int, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
type Op struct {
|
||||
// Your definitions here.
|
||||
// Field names must start with capital letters,
|
||||
@@ -37,12 +37,11 @@ type KVServer struct {
|
||||
// Your definitions here.
|
||||
}
|
||||
|
||||
|
||||
func (kv *KVServer) Get(args *GetArgs, reply *GetReply) {
|
||||
// Your code here.
|
||||
}
|
||||
|
||||
// unlike in lab 2, neither Put nor Append should return a value.
|
||||
// this is already reflected in the PutAppendReply struct.
|
||||
func (kv *KVServer) Put(args *PutAppendArgs, reply *PutAppendReply) {
|
||||
// Your code here.
|
||||
}
|
||||
@@ -86,7 +85,7 @@ func StartKVServer(servers []*labrpc.ClientEnd, me int, persister *raft.Persiste
|
||||
// call labgob.Register on structures you want
|
||||
// Go's RPC library to marshall/unmarshall.
|
||||
labgob.Register(Op{})
|
||||
|
||||
|
||||
kv := new(KVServer)
|
||||
kv.me = me
|
||||
kv.maxraftstate = maxraftstate
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"math/rand"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -458,7 +459,7 @@ func TestMemAppend2(t *testing.T) {
|
||||
cfg.end()
|
||||
}
|
||||
|
||||
func TestMemPutMany(t *testing.T) {
|
||||
func TestMemPutManyClients(t *testing.T) {
|
||||
const (
|
||||
NCLIENT = 100_000
|
||||
MEM = 1000
|
||||
@@ -477,7 +478,7 @@ func TestMemPutMany(t *testing.T) {
|
||||
// allow threads started by labrpc to start
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
cfg.begin("Test: memory use many puts")
|
||||
cfg.begin("Test: memory use many put clients")
|
||||
|
||||
runtime.GC()
|
||||
runtime.GC()
|
||||
@@ -508,7 +509,7 @@ func TestMemPutMany(t *testing.T) {
|
||||
cfg.end()
|
||||
}
|
||||
|
||||
func TestMemGetMany(t *testing.T) {
|
||||
func TestMemGetManyClients(t *testing.T) {
|
||||
const (
|
||||
NCLIENT = 100_000
|
||||
)
|
||||
@@ -516,7 +517,7 @@ func TestMemGetMany(t *testing.T) {
|
||||
cfg := make_config(t, false)
|
||||
defer cfg.cleanup()
|
||||
|
||||
cfg.begin("Test: memory use many gets")
|
||||
cfg.begin("Test: memory use many get client")
|
||||
|
||||
ck := cfg.makeClient()
|
||||
ck.Put("0", "")
|
||||
@@ -560,3 +561,46 @@ func TestMemGetMany(t *testing.T) {
|
||||
|
||||
cfg.end()
|
||||
}
|
||||
|
||||
func TestMemManyAppends(t *testing.T) {
|
||||
const (
|
||||
N = 1000
|
||||
MEM = 1000
|
||||
)
|
||||
|
||||
cfg := make_config(t, false)
|
||||
defer cfg.cleanup()
|
||||
|
||||
cfg.begin("Test: memory use many appends")
|
||||
|
||||
ck := cfg.makeClient()
|
||||
rdVal := randValue(MEM)
|
||||
|
||||
runtime.GC()
|
||||
runtime.GC()
|
||||
|
||||
var st runtime.MemStats
|
||||
runtime.ReadMemStats(&st)
|
||||
m0 := st.HeapAlloc
|
||||
|
||||
for i := 0; i < N; i++ {
|
||||
ck.Append("k", rdVal)
|
||||
}
|
||||
|
||||
runtime.GC()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
runtime.GC()
|
||||
|
||||
runtime.ReadMemStats(&st)
|
||||
m1 := st.HeapAlloc
|
||||
if m1 >= 3*MEM*N {
|
||||
t.Fatalf("error: server using too much memory m0 %d m1 %d\n", m0, m1)
|
||||
}
|
||||
|
||||
log.Printf("m0 %d m1 %d\n", m0, m1)
|
||||
|
||||
cfg.deleteClient(ck)
|
||||
cfg.end()
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import "fmt"
|
||||
import "6.5840/mr"
|
||||
import "plugin"
|
||||
import "os"
|
||||
import "io"
|
||||
import "log"
|
||||
import "io/ioutil"
|
||||
import "sort"
|
||||
|
||||
// for sorting by key.
|
||||
@@ -41,7 +41,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("cannot open %v", filename)
|
||||
}
|
||||
content, err := io.ReadAll(file)
|
||||
content, err := ioutil.ReadAll(file)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot read %v", filename)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user