This commit is contained in:
Upamanyu Sharma
2024-04-02 14:57:06 -04:00
parent ab9b8d2f68
commit db55e49c10
5 changed files with 61 additions and 18 deletions

View File

@@ -110,11 +110,11 @@ check_lab5b() {
check_cmd go test -c check_cmd go test -c
# also check other labs/parts # also check other labs/parts
cd "$tmpdir" cd "$tmpdir"
check_lab4a check_lab5a
cd "$tmpdir"
check_lab4
cd "$tmpdir" cd "$tmpdir"
check_lab3 check_lab3
cd "$tmpdir"
check_lab2
} }
check_cmd() { check_cmd() {

View File

@@ -29,7 +29,7 @@ func MakeClerk(servers []*labrpc.ClientEnd) *Clerk {
// keeps trying forever in the face of all other errors. // keeps trying forever in the face of all other errors.
// //
// you can send an RPC with code like this: // 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) // the types of args and reply (including whether they are pointers)
// must match the declared types of the RPC handler function's // 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. // shared by Put and Append.
// //
// you can send an RPC with code like this: // 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) // the types of args and reply (including whether they are pointers)
// must match the declared types of the RPC handler function's // must match the declared types of the RPC handler function's

View File

@@ -1,13 +1,12 @@
package kvraft package kvraft
import ( import (
"log"
"sync"
"sync/atomic"
"6.5840/labgob" "6.5840/labgob"
"6.5840/labrpc" "6.5840/labrpc"
"6.5840/raft" "6.5840/raft"
"log"
"sync"
"sync/atomic"
) )
const Debug = false const Debug = false
@@ -19,6 +18,7 @@ func DPrintf(format string, a ...interface{}) (n int, err error) {
return return
} }
type Op struct { type Op struct {
// Your definitions here. // Your definitions here.
// Field names must start with capital letters, // Field names must start with capital letters,
@@ -37,12 +37,11 @@ type KVServer struct {
// Your definitions here. // Your definitions here.
} }
func (kv *KVServer) Get(args *GetArgs, reply *GetReply) { func (kv *KVServer) Get(args *GetArgs, reply *GetReply) {
// Your code here. // 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) { func (kv *KVServer) Put(args *PutAppendArgs, reply *PutAppendReply) {
// Your code here. // Your code here.
} }

View File

@@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"math/rand" "math/rand"
"runtime" "runtime"
"strconv" "strconv"
@@ -458,7 +459,7 @@ func TestMemAppend2(t *testing.T) {
cfg.end() cfg.end()
} }
func TestMemPutMany(t *testing.T) { func TestMemPutManyClients(t *testing.T) {
const ( const (
NCLIENT = 100_000 NCLIENT = 100_000
MEM = 1000 MEM = 1000
@@ -477,7 +478,7 @@ func TestMemPutMany(t *testing.T) {
// allow threads started by labrpc to start // allow threads started by labrpc to start
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
cfg.begin("Test: memory use many puts") cfg.begin("Test: memory use many put clients")
runtime.GC() runtime.GC()
runtime.GC() runtime.GC()
@@ -508,7 +509,7 @@ func TestMemPutMany(t *testing.T) {
cfg.end() cfg.end()
} }
func TestMemGetMany(t *testing.T) { func TestMemGetManyClients(t *testing.T) {
const ( const (
NCLIENT = 100_000 NCLIENT = 100_000
) )
@@ -516,7 +517,7 @@ func TestMemGetMany(t *testing.T) {
cfg := make_config(t, false) cfg := make_config(t, false)
defer cfg.cleanup() defer cfg.cleanup()
cfg.begin("Test: memory use many gets") cfg.begin("Test: memory use many get client")
ck := cfg.makeClient() ck := cfg.makeClient()
ck.Put("0", "") ck.Put("0", "")
@@ -560,3 +561,46 @@ func TestMemGetMany(t *testing.T) {
cfg.end() 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()
}

View File

@@ -10,8 +10,8 @@ import "fmt"
import "6.5840/mr" import "6.5840/mr"
import "plugin" import "plugin"
import "os" import "os"
import "io"
import "log" import "log"
import "io/ioutil"
import "sort" import "sort"
// for sorting by key. // for sorting by key.
@@ -41,7 +41,7 @@ func main() {
if err != nil { if err != nil {
log.Fatalf("cannot open %v", filename) log.Fatalf("cannot open %v", filename)
} }
content, err := io.ReadAll(file) content, err := ioutil.ReadAll(file)
if err != nil { if err != nil {
log.Fatalf("cannot read %v", filename) log.Fatalf("cannot read %v", filename)
} }