I have been writing some rpc code in go, using the standard library.
My system is kubuntu 18.10 64 bit all updates applied in conjunction with golang 1.11.
In an update to my initial assumptions about memory usage, they turned out to be incorrect so here is my updated question. The question still reates to a constant climb in memory consumption.
Update:
I have done some further investigation, and, I am probably still not understanding correctly.
I wrote a simple test server and client as follows:
Client:
package main
import (
"net/rpc"
)
import (
"fmt"
"log"
)
type Args struct {
ThrottleName string
BatchSize int
}
func main() {
throttle, err := rpc.Dial("tcp", "127.0.0.1:1234")
if err != nil {
log.Fatal("dialing:", err)
}
fmt.Println("done dial")
var reply int
var tc = Args{ThrottleName: "a", BatchSize: 10}
for {
_ = throttle.Call("Task.Throttle", tc, &reply)
fmt.Println(reply)
}
}
Server:
package main
import (
"net"
"net/rpc"
"time"
)
type Args struct {
ThrottleName string
BatchSize int
}
type Task int
func (t *Task) Throttle(args *Args, reply *int) error {
time.Sleep(1 * time.Microsecond)
//reply = 0
return nil
}
func main() {
task := new(Task)
rpc.Register(task)
listener, _ := net.Listen("tcp", ":1234")
defer listener.Close()
rpc.Accept(listener)
}
I then started the server. Checked the memory use using:
ps -eo size,command --sort -size | grep rpctest | awk '{ hr=$1/1024 ; sum +=hr} END {print sum}'
This registered about 140mb, I then started the client, the memory usage climbs over time, after 5.5hours it had reached 359mb. I cannot confirm that it had finished climbing.
I then stopped the client and after 2 hours the memory usage was still at 359mb.
I guess my updated question are:
Am i do something wrong?
Why does the memory use not at least drop back after the client exits?
Why does memory keep rising through use?
Excuse the appalling error checking.
Final addendum I also tried:
stress --vm-bytes $(awk '/MemAvailable/{printf "%d
", $2}' < /proc/meminfo)k --vm-keep -m 1
In case the system was not reclaiming the memory from go.