This commit is contained in:
Frans Kaashoek
2024-02-12 08:09:47 -05:00
parent 420dd2208d
commit 5b5ae16e92
2 changed files with 48 additions and 34 deletions

View File

@@ -6,7 +6,6 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log"
"math/rand" "math/rand"
"runtime" "runtime"
"strconv" "strconv"
@@ -373,7 +372,7 @@ const (
) )
func TestMemGet2(t *testing.T) { func TestMemGet2(t *testing.T) {
const MEM = 100 // in MiB const MEM = 10 // in MiB
cfg := make_config(t, true) cfg := make_config(t, true)
defer cfg.cleanup() defer cfg.cleanup()
@@ -408,7 +407,7 @@ func TestMemGet2(t *testing.T) {
} }
func TestMemPut2(t *testing.T) { func TestMemPut2(t *testing.T) {
const MEM = 100 // in MiB const MEM = 10 // in MiB
cfg := make_config(t, false) cfg := make_config(t, false)
defer cfg.cleanup() defer cfg.cleanup()
@@ -423,6 +422,7 @@ func TestMemPut2(t *testing.T) {
ck1.Put("k", "") ck1.Put("k", "")
runtime.GC() runtime.GC()
var st runtime.MemStats var st runtime.MemStats
runtime.ReadMemStats(&st) runtime.ReadMemStats(&st)
m := st.HeapAlloc / MiB m := st.HeapAlloc / MiB
@@ -433,7 +433,7 @@ func TestMemPut2(t *testing.T) {
} }
func TestMemAppend2(t *testing.T) { func TestMemAppend2(t *testing.T) {
const MEM = 100 // in MiB const MEM = 10 // in MiB
cfg := make_config(t, false) cfg := make_config(t, false)
defer cfg.cleanup() defer cfg.cleanup()
@@ -458,51 +458,57 @@ func TestMemAppend2(t *testing.T) {
cfg.end() cfg.end()
} }
func TestMemPutMany2(t *testing.T) { func TestMemPutMany(t *testing.T) {
const ( const (
NPUT = 1_000_000 NCLIENT = 100_000
MEM = 1000 MEM = 1000
) )
cfg := make_config(t, false) cfg := make_config(t, false)
defer cfg.cleanup() defer cfg.cleanup()
cfg.begin("Test: memory use many puts")
ck := cfg.makeClient()
v := randValue(MEM) v := randValue(MEM)
ck.Put("k", v) cks := make([]*Clerk, NCLIENT)
for i, _ := range cks {
cks[i] = cfg.makeClient()
}
// allow threads started by labrpc to exit // allow threads started by labrpc to start
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
cfg.begin("Test: memory use many puts")
runtime.GC()
runtime.GC() runtime.GC()
var st runtime.MemStats var st runtime.MemStats
runtime.ReadMemStats(&st) runtime.ReadMemStats(&st)
m0 := st.HeapAlloc m0 := st.HeapAlloc
for i := 0; i < NPUT; i++ { for i := 0; i < NCLIENT; i++ {
ck.Put("k", v) cks[i].Put("k", v)
} }
// allow threads started by labrpc to exit
time.Sleep(1 * time.Second)
runtime.GC() runtime.GC()
time.Sleep(1 * time.Second)
runtime.GC()
runtime.ReadMemStats(&st) runtime.ReadMemStats(&st)
m1 := st.HeapAlloc m1 := st.HeapAlloc
f := (float64(m1) - float64(m0)) / NCLIENT
//log.Printf("mem m0 %d m1 %d\n", m0, m1) if m1 > m0+(NCLIENT*200) {
t.Fatalf("error: server using too much memory %d %d (%.2f per client)\n", m0, m1, f)
if m1 > m0+NPUT/10 {
t.Fatalf("error: server using too much memory %d %d\n", m0, m1)
} }
for _, ck := range cks {
cfg.deleteClient(ck)
}
cfg.end() cfg.end()
} }
func TestMemGetMany2(t *testing.T) { func TestMemGetMany(t *testing.T) {
const ( const (
NCLIENT = 100_000 NCLIENT = 100_000
) )
@@ -516,6 +522,14 @@ func TestMemGetMany2(t *testing.T) {
ck.Put("0", "") ck.Put("0", "")
cfg.deleteClient(ck) cfg.deleteClient(ck)
cks := make([]*Clerk, NCLIENT)
for i, _ := range cks {
cks[i] = cfg.makeClient()
}
// allow threads started by labrpc to start
time.Sleep(1 * time.Second)
runtime.GC() runtime.GC()
runtime.GC() runtime.GC()
@@ -524,24 +538,24 @@ func TestMemGetMany2(t *testing.T) {
m0 := st.HeapAlloc m0 := st.HeapAlloc
for i := 0; i < NCLIENT; i++ { for i := 0; i < NCLIENT; i++ {
ck := cfg.makeClient() cks[i].Get("0")
ck.Get("0")
cfg.deleteClient(ck)
} }
runtime.GC()
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
runtime.GC() runtime.GC()
runtime.GC()
//runtime.GC()
runtime.ReadMemStats(&st) runtime.ReadMemStats(&st)
m1 := st.HeapAlloc m1 := st.HeapAlloc
f := (float64(m1) - float64(m0)) / NCLIENT
if m1 >= m0+NCLIENT*10 {
t.Fatalf("error: server using too much memory m0 %d m1 %d (%.2f per client)\n", m0, m1, f)
}
log.Printf("mem m0 %d m1 %d\n", m0, m1) for _, ck := range cks {
cfg.deleteClient(ck)
if m1 >= m0+NCLIENT {
t.Fatalf("error: server using too much memory m0 %d m1 %d\n", m0, m1)
} }
cfg.end() 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 := ioutil.ReadAll(file) content, err := io.ReadAll(file)
if err != nil { if err != nil {
log.Fatalf("cannot read %v", filename) log.Fatalf("cannot read %v", filename)
} }