小编Noo*_*bie的帖子

container_memory_working_set_bytes 与 process_resident_memory_bytes 和total_rss 之间的关系

我希望了解以下关系

container_memory_working_set_bytes vs process_resident_memory_bytes vs Total_rss (container_memory_rss) + file_mapped以便更好地装备系统以对 OOM 可能性进行警报。

在此输入图像描述

如果容器/pod 运行单个进程来执行用 Go 编写的编译程序,这似乎违背了我的理解(现在让我感到困惑) 。

为什么两者之间的差异container_memory_working_set_bytes如此之大(接近10倍)process_resident_memory_bytes

container_memory_working_set_bytes而且和之间的关系在这里很奇怪,这是我读完container_memory_rss + file_mapped之后没有想到的

匿名和交换缓存内存总量(包括透明大页),它等于 memory.status 文件中的total_rss 值。不应将其与真实驻留集大小或 cgroup 使用的物理内存量相混淆。rss + file_mapped 将为您提供 cgroup 的驻留集大小。它不包括换出的内存。它确实包含来自共享库的内存,只要这些库中的页面实际上位于内存中。它确实包括所有堆栈和堆内存。

因此,cgroup总驻留集大小是rss + file_mapped如何小于container_working_set_bytes给定 cgroup 中运行的容器的值的

这让我觉得这个统计数据有些不正确。

以下是用于构建上图的 PROMQL

  • process_resident_memory_bytes{container="sftp-downloader"}
  • container_memory_working_set_bytes{container="sftp-downloader"}
  • go_memstats_heap_alloc_bytes{container="sftp-downloader"}
  • 容器_内存_映射_文件{容器=“sftp-downloader”} + 容器_内存_rss{容器=“sftp-downloader”}

go cgroups kubernetes cadvisor kubernetes-metrics

10
推荐指数
1
解决办法
8347
查看次数

计算 gdb 和 lldb 中的表达式

我正在尝试了解 GDB 和 LLDB,以便我可以随时有效地使用它来调试我的程序。

但似乎我被卡住了我不知道如何打印 C 库函数的输出,例如powstrnlen等等。如果我想探索那里的输出。

以下是 LLDB 和 GDB 输出。

   3    int main(int argc,char *argv[]) {
   4       int a = pow(3,2);
-> 5       printf("the value of a is %d",a);
   6       return 0;
   7    }
(lldb) print pow(3,1)
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
error: 'pow' has unknown return type; cast the call to its declared return type
(lldb) print strlen("abc")
warning: could …
Run Code Online (Sandbox Code Playgroud)

gcc gdb lldb

7
推荐指数
1
解决办法
8935
查看次数

获取 ActiveRecord 中的 Union 所有结果

Rails 中如何获取 UNION 运算结果?

鉴于我有以下 SQL 语句

SELECT  "sip_trunks".* FROM "sip_trunks" WHERE "sip_trunks"."default" = t LIMIT 1 UNION ALL SELECT  "sip_trunks".* FROM "sip_trunks" WHERE "sip_trunks"."default" = f LIMIT 1 
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经成功地使用 AREL 和 union all 语句构建了 SQL。

SipTrunk.where(default: true).limit(1).union(:all,SipTrunk.where(default: false).limit(1))

Run Code Online (Sandbox Code Playgroud)

但尝试查询此结果和 AREL 即Arel::Nodes::UnionAll,我无法获得数据库结果。

同样to_sql在语句上运行会产生这样的 SQL..

( SELECT  "sip_trunks".* FROM "sip_trunks" WHERE "sip_trunks"."default" = $1 LIMIT 1 UNION ALL SELECT  "sip_trunks".* FROM "sip_trunks" WHERE "sip_trunks"."default" = $2 LIMIT 1 )
Run Code Online (Sandbox Code Playgroud)

这看起来像是一个准备好的语句,但我在数据库中没有看到任何准备好的语句

尝试使用上面的 SQLfind_by_sql

SipTrunk.find_by_sql(SipTrunk.where(default: true).limit(1).union(:all,SipTrunk.where(default: false).limit(1)).to_sql,[['default',true],['default',false]])
Run Code Online (Sandbox Code Playgroud)

出现以下错误 …

union activerecord ruby-on-rails arel ruby-on-rails-4

7
推荐指数
1
解决办法
8792
查看次数

睡眠0有特殊意义吗?

sleep 0在我的客户项目中看到了很多用法.

代码看起来像这样.

while true 
  ...
  ...
  sleep 0
end
Run Code Online (Sandbox Code Playgroud)

通过一些答案读,好喜欢这种似乎sleep 0具有一定的指导意义.

我现在想知道的是,在时间片期间调度其他线程运行(如果它们等待运行)0是一个像Ruby或python这样的lang VM的工作,或者它是内核的工作.

顺便说一句,Ruby VM会sleep 0像上面链接中提到的那样尊重它.

ruby unix linux sleep

6
推荐指数
1
解决办法
896
查看次数

缺少模块ltn12的依赖项

我正在创建一个使用sendgrid发送邮件的模块(仍处于早期阶段)

我有跟随rockspec

package = "sendgrid"
version = "0.1.0-1"
source = {
   url = "git://github.com/meetme2meat/sendgrid"
}
description = {
   summary = "Sendgrid V3 API to send mail",
   detailed = [[
      Send email using sendgrid.
   ]],
   homepage = "https://github.com/meetme2meat/sendgrid",
   license = "MIT"
}
dependencies = {
   "lua >= 5.2, < 5.4",
   "lua-cjson >= 2.0.0, <= 2.1.0",
   "luasocket >= 3.0rc1",
   "luasec"
}
build = {
   type = "builtin",
   modules = {
      sendgrid = "sendgrid.lua"
   }
}
Run Code Online (Sandbox Code Playgroud)

下面需要使用sendgrid api发送电子邮件所需的模块

-- sengrid.lua file.
local ltn12 …
Run Code Online (Sandbox Code Playgroud)

lua luarocks

6
推荐指数
0
解决办法
131
查看次数

psycopg2 中的事务支持

我对阅读psycopg2文档关于它如何处理事务(除了使用它与with语句)感到有点困惑。

通读文档我明白了

默认情况下,Psycopg 在执行第一个命令之前打开一个事务:如果不调用 commit(),任何数据操作的效果都将丢失。

假设上述陈述是正确的

dbconn = psycopg2.connect(...)   cursor = dbconn.cursor()
cursor.execute("insert record into a") 
cursor.execute("insert record into b")

cursor.execute("insert record into c") // This throw integrity error.
cursor.execute("commit") // this logs "WARNING:  there is no transaction in progress"
Run Code Online (Sandbox Code Playgroud)

对于数据的操纵ab就会迷失方向

但据我所知,这在 PostgreSQL 上并没有发生。我肯定在这里错过了一些东西,但现在我不确定什么以及在哪里。

postgresql psycopg2

5
推荐指数
1
解决办法
1973
查看次数

container_memory_rss 与使用的节点内存的关系

我试图理解与node_memory_used有关的container_memory_rss或container_memory_working_set_bytes ,即(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes

这就是我的意思

PROMQL 1:

sum(container_memory_rss) by (instance) / 1024 / 1024 / 1024

{instance="172.19.51.8:10250"}        7.537441253662109
Run Code Online (Sandbox Code Playgroud)

PROMQL 2:

sum(node_memory_MemTotal_bytes - node_memory_MemAvailable_bytes) by (instance) / 1024 / 1024 / 1024

{instance="172.19.51.8:9100"}         2.2688369750976562
Run Code Online (Sandbox Code Playgroud)

PROMQL 3:

sum(container_memory_working_set_bytes) by (instance) / 1024 / 1024 / 1024

{instance="172.19.51.8:10250"}        9.285114288330078
Run Code Online (Sandbox Code Playgroud)

PROMQL 4:

sum(node_memory_MemAvailable_bytes) by (instance) / 1024 / 1024 / 1024

{instance="172.19.51.8:9100"}         13.356605529785156
Run Code Online (Sandbox Code Playgroud)

所以如果一个 Pod 总是运行在一个 Node 上。我无法理解为什么container_memory_rsscontainer_memory_working_set_bytes大于node_memory_used

即 PROMQL 1 和 PROMQL 3 的值远大于 …

kubernetes prometheus cadvisor kubernetes-pod

5
推荐指数
1
解决办法
1714
查看次数

引导下的libuv是使用epoll还是在unix中选择(2)

我一直在阅读nodejs如何使用libuv来执行异步I/O. 阅读更多关于它的感觉让我觉得它几乎听起来像select(2)和epoll.

所以,我的问题是,如果我使用libuv(通过节点)是内部我使用select(2)或epoll.

libuv是unix中的select(2)和epoll系统调用的包装吗?

unix epoll node.js libuv select2

2
推荐指数
1
解决办法
1353
查看次数

在ruby中运行Manual GC是一种好习惯

我在谷歌上看到很多,ruby没有向操作系统发布内存,我也理解这一点,因为从操作系统分配内存是一个代价高昂的公平.

这导致我问这个问题

如果开发人员希望Ruby将内存从ruby释放回操作系统,他们是如何做到的.

- 我想答案是手动触发GCRuby中的一个.

但是建议在生产应用程序上执行(运行手动GC).

我正在考虑在Celluloid中创建一个单独的线程(或Actor)来每2小时启动一次GC.

谁能建议.以上解决方案是否适合生产.

注意:我想我也知道GC.start(意味着在Ruby中停止整个世界)

注意:Ruby版本2.2.2 MRI Centos 4G RAM,4核心.

以下是问题http://pastebin.com/rYdYwxLJ的原因

ruby garbage-collection

1
推荐指数
2
解决办法
2350
查看次数