简体   繁体   English

将内存请求设置为小于限制的用例是什么? K8s

[英]What is the use case of setting memory request less than limit in . K8s

I understand the use case of setting CPU request less than limit - it allows for CPU bursts in each container if the instances has free CPU hence resulting in max CPU utilization. 我知道将CPU请求设置为小于限制的用例-如果实例具有可用的CPU,则允许每个容器中的CPU突发,从而导致最大的CPU利用率。 However, I cannot really find the use case for doing the same with memory. 但是,我真的找不到用内存做同样的用例。 Most application don't release memory after allocating it, so effectively applications will request up to 'limit' memory (which has the same effect as setting request = limit). 大多数应用程序在分配内存后不会释放内存,因此有效地,应用程序将请求最多“限制”的内存(与设置request = limit的作用相同)。 The only exception is containers running on an instance that already has all its memory allocated. 唯一的例外是在已分配了所有内存的实例上运行的容器。 I don't really see any pros in this, and the cons are more nondeterministic behaviour that is hard to monitor (one container having higher latencies than the other due to heavy GC). 我在这方面并没有真正的优点,缺点是更不确定的行为,很难监控(由于GC繁重,一个容器的延迟比另一个容器高)。 Only use case I can think of is a shaded in memory cache, where you want to allow for a spike in memory usage. 我能想到的唯一用例是内存缓存中的阴影,您希望允许内存使用量激增。 But even in this case one would be running the risk of of one of the nodes underperforming. 但是即使在这种情况下,也可能存在节点之一表现不佳的风险。

Maybe not a real answer, but a point of view on the subject. 也许不是一个真正的答案,而是关于这个问题的观点。

The difference with the limit on CPU and Memory is what happens when the limit is reached. 达到限制后,将发生CPU和内存限制的差异。 In case of the CPU, the container keeps running but the CPU usage is limited. 如果使用CPU,容器将继续运行,但是CPU使用率受到限制。 If memory limit is reached, container gets killed and restarted. 如果达到内存限制,容器将被杀死并重新启动。

In my use case, I often set the memory request to the amount of memory my application uses on average, and the limit to +25%. 在我的用例中,我经常将内存请求设置为应用程序平均使用的内存量,并且将限制设置为+ 25%。 This allows me to avoid container killing most of the time (which is good) but of course it exposes me to memory overallocation (and this could be a problem as you mentioned). 这使我可以避免大部分时间都被容器杀死(这很好),但是当然,这使我面临内存过度分配的问题(这可能是您提到的问题)。

Actually the topic you mention is interesting and in the meantime complex, just as Linux memory management is. 实际上,您提到的主题很有趣,与此同时也很复杂,就像Linux内存管理一样。 As we know when the process is using more memory than the limit it will quickly move up on the potential "to-kill" process "ladder". 我们知道,当进程使用的内存超过限制时,它将迅速上升到潜在的“杀死”进程“阶梯”。 Going further, the purpose of limit is to tell the kernel when it should consider the process to be potentially killed. 更进一步,限制的目的是告诉内核何时应该考虑可能终止该进程。 Requests on the other hand are a direct statement "my container will need this much memory", but other than that they provide valuable information to the Scheduler about where can the Pod be scheduled (based on available Node resources). 另一方面,请求是直接声明“我的容器将需要这么多的内存”,但除此之外,它们还向调度程序提供有关可在何处调度Pod的宝贵信息(基于可用的Node资源)。

If there is no memory request and high limit, Kubernetes will default the request to the limit (this might result in scheduling fail, even if the pods real requirements are met). 如果没有内存请求和上限,Kubernetes会将请求默认为限制(即使满足Pod的实际要求,这也可能导致调度失败)。

If you set a request, but not limit - container will use the default limit for namespace (if there is none, it will be able to use the whole available Node memory) 如果设置一个请求,但没有限制-容器将使用名称空间的默认限制(如果没有限制,它将能够使用整个可用的Node内存)

Setting memory request which is lower than limit you will give your pods room to have activity bursts. 设置的内存请求低于限制,您将为豆荚空间腾出活动空间。 Also you make sure that a memory which is available for Pod to consume during boost is actually a reasonable amount. 另外,还要确保Pod在增强期间可以消耗的内存实际上是合理的数量。

Setting memory limit == memory request is not desirable simply because activity spikes will put it on a highway to be OOM killed by Kernel. 设置内存限制==内存请求并不理想,因为活动高峰会将其放置在高速公路上,以被内核杀死。 The memory limits in Kubernetes cannot be throttled, if there is a memory pressure that is the most probable scenario (lets also remember that there is no swap partition). 如果存在最可能出现的内存压力,则不能限制Kubernetes中的内存限制(还请记住,没有交换分区)。

Quoting Will Tomlin and his interesting article on Requests vs Limits which I highly recommend: 引用威尔·汤姆林Will Tomlin)和他关于“ 请求与限制”的有趣文章,我强烈建议:

You might be asking if there's reason to set limits higher than requests. 您可能会问是否有理由将限制设置为高于要求。 If your component has a stable memory footprint, you probably shouldn't since when a container exceeds its requests, it's more likely to be evicted if the worker node encounters a low memory condition. 如果您的组件具有稳定的内存占用,则可能不应该这样做,因为当容器超出其请求时,如果工作程序节点遇到内存不足的情况,则很可能将其驱逐。

To summarize - there is no straight and easy answer. 总结-没有简单直接的答案。 You have to determine your memory requirements and use monitoring and alerting tools to have control and be ready to change/adjust the configuration accordingly to needs. 您必须确定内存需求,并使用监视和警报工具进行控制,并准备根据需要更改/调整配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM