dtqf81594 2017-03-07 20:20
浏览 61
已采纳

带2个CPU的服务器

I'm building a GRPC server in GO and I want increase its performance. I've increased my machine and put 2CPUS in order to make it better but I noticed that my server doesn't use all cpu cores and I couldn't find a way to fix it (I've run some tests to make the server worker harder). It seems like my server uses 1 cpu a lot and the other not. My load average stay above 1 what means that my server is full of requests but when I see the performance in netdata there's only one CPU working.

This is my grpc code:

package main
import (
    "fmt"
    "runtime"
    "log"
    "net"
    "google.golang.org/grpc"
    "golang.org/x/net/context"
    "google.golang.org/grpc/reflection"
    pb "teste/prototeste"

)
func (s *server) Test(ctx context.Context, n *pb.TestRequest)      (*pb.TestReply, error){
    return &pb.TestReply{Message: n.Name}, nil
}

type server struct{}

const (
    port = ":50051"
)

func main(){

    numOfCores := runtime.NumCPU()
    fmt.Println(numOfCores)
    runtime.GOMAXPROCS(numOfCores)
    lis, err := net.Listen("tcp", port)
    if err != nil {
        log.Fatalf("failed to listen: %v", err)
    }
    s := grpc.NewServer()
    pb.RegisterGreeterServer(s, &server{})
    // Register reflection service on gRPC server.
    reflection.Register(s)

    s.Serve(lis)

}

Notice that in Serve function there's a goroutine that allow the server accept multiple requests in parallel.

API reference grpc in go

This is my cpu usage

Any tips to how to solve this and make my server use 2 cpus?

  • 写回答

1条回答 默认 最新

  • dou47732 2017-04-20 20:34
    关注

    In gRPC, each server handler runs in its own goroutine. From there it is up to the Go scheduler to determine what CPUs to schedule them on. Depending on what your server handlers are doing, system load, etc, it's possible they could all end up scheduled on the same CPU.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型