如何指定Web API的CPU/RAM资源?

huangapple go评论92阅读模式
英文:

How to specify the CPU/RAM resources of Web API?

问题

我已创建了一个C# .NET Core Web API。我正在使用Dockerfile和docker-compose来运行该应用程序。在我的测试之后,我将发布它到Kubernetes。

所以我的问题是:

我如何指定此应用程序的最佳CPU和内存限制需求?实际上我需要多少个Pod?我如何测量和指定我的需求?

英文:

I have created a C# .NET Core Web API. I am using a Dockerfile and docker-compose to run the application. After my tests, I will publish it to Kubernetes.

So my problem is:

How can I specify the optimum CPU and memory limit needs of this application? And how many pods will I need actually? How can I measure and specify my needs?

答案1

得分: 1

我不知道一个C#应用程序需要多少资源,我的建议是分配1GB的RAM和1个CPU。在几天内监视实际使用的资源,然后决定是否降低或增加它们。无论如何,资源并不是静态值,随着时间的推移可以更改。

简而言之:

对于你提出的问题,没有精确的答案,因为你需要经验,了解应用程序的功能并知道它需要什么。

让我们举一些具体的例子。
如果应用程序是用JavaScript编写的,并且没有特别的操作,那么可以保持资源相对较低,例如500Mi的CPU和500MB的RAM。
如果该应用程序使用的内存超出预期或执行了大量计算,可以考虑增加资源限制。
如果该应用程序位于整个系统的核心,您可能需要考虑分配更多的资源。

我给你的建议是在生产环境中保持Pod的资源限制高于开发环境,并随着时间的推移检查这些资源是否足够或是否需要增加它们。

显著增加资源并不总是正确的做法,有时增加Pod的数量可能就足够了。在这种情况下,您可以使用HPA。
一旦有了更多的数据,您可以考虑更改资源和Pod的数量。

我个人更喜欢具有低资源的许多Pod,而不是具有高资源的少数Pod,但每个应用程序都是不同的。

英文:

I don't know how many resources a C# application needs and what I would do is give 1Gb of RAM and 1Cpu. Monitor the resources actually used over several days and then decide to lower or increase them. In any case, resources are not static values ​​and can be changed over time.

tl;dr

There is no precise answer for the question you asked because you have to have experience and understand what the application does and know what it needs.

Let's take some concrete examples.
In case the application is written in javascript and does nothing in particular then it is possible to keep the resources relatively low, for example 500Mi CPU and 500Mb Ram.
If this application uses more memory than expected or does a lot of calculations, you may consider increasing the limits.
In case this application is at the heart of the entire system, you might be thinking about standing higher with resources.

The advice I give you is to keep the pod limits in the production environment higher than in the development environment and check over time if these resources are sufficient or if it is necessary to increase them.

It is not always correct to significantly increase resources, sometimes it can be sufficient to increase the number of pods. In this case you can use HPA .
Once you have more data you can consider changing the resources and number of pods.

I personally prefer to have many pods with low resources rather than a few pods with high resources, but every application is different

huangapple
  • 本文由 发表于 2023年8月5日 03:32:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76838720.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定