dongyupen6269 2018-12-05 09:44
浏览 57

去rpc内存泄漏还是缺乏了解?

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 如何在scanpy上做差异基因和通路富集?
    • ¥20 关于#硬件工程#的问题,请各位专家解答!
    • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
    • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
    • ¥30 截图中的mathematics程序转换成matlab
    • ¥15 动力学代码报错,维度不匹配
    • ¥15 Power query添加列问题
    • ¥50 Kubernetes&Fission&Eleasticsearch
    • ¥15 報錯:Person is not mapped,如何解決?
    • ¥15 c++头文件不能识别CDialog