Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么代码方式关闭不了bvar sampling线程? #2244

Open
haolujun opened this issue May 12, 2023 · 8 comments
Open

为什么代码方式关闭不了bvar sampling线程? #2244

haolujun opened this issue May 12, 2023 · 8 comments

Comments

@haolujun
Copy link

Describe the bug (描述bug)
如何用代码的方式关闭sampling 线程?

To Reproduce (复现方法)
namespace bvar {
namespace detai {
DECLARE_bool(bvar_enable_sampling);
}
}

int main () {
bvar::detail::FLAGS_bvar_enable_sampling = false;
return 0;
}

Expected behavior (期望行为)
关闭bvar的sampling线程。

Versions (各种版本)
OS:
Linux c1089df56064 4.9.70-040970-generic #201712161132 SMP Sat Dec 16 16:33:52 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Compiler:
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

brpc: 1.4.0
protobuf: protobuf-3.19.5

Additional context/screenshots (更多上下文/截图)

:W20230511 18:29:16.687115 87 sampler.cpp:194] bvar is busy at sampling for 2 seconds!

@wwbmmm
Copy link
Contributor

wwbmmm commented May 12, 2023

使用google::SetCommandLineOption("bvar_enable_sampling", "0") 试试

@yanglimingcn
Copy link
Contributor

关闭这个对监控指标会有啥问题吗?
比如,curl http://xxx:port/vars

@leaf-potato
Copy link
Contributor

关闭这个对监控指标会有啥问题吗? 比如,curl http://xxx:port/vars

@yanglimingcn bvar的统计值都会失效,参考#1891

@ghost
Copy link

ghost commented Nov 9, 2023

image

这个Flags使用是在main函数之前的,所以在main函数之后任何对其操作貌似都不会关闭统计线程。

@leaf-potato
Copy link
Contributor

leaf-potato commented Nov 19, 2023

image

这个Flags使用是在main函数之前的,所以在main函数之后任何对其操作貌似都不会关闭统计线程。

注释想表达:SamplerCollector单例在main函数之前构造的&启动了线程,所以flag实现不能放在SamplerCollector类中,因为不会生效。所以才放到了Sampler::schedule函数这儿控制。

另外在echo_c++例子中使用下面两种方式看着都可以正确关闭:

  1. bvar::detail::FLAGS_bvar_enable_sampling = false;
  2. google::SetCommandLineOption("bvar_enable_sampling", "false");

@ghost
Copy link

ghost commented Dec 1, 2023

image
这个Flags使用是在main函数之前的,所以在main函数之后任何对其操作貌似都不会关闭统计线程。

注释想表达:SamplerCollector单例在main函数之前构造的&启动了线程,所以flag实现不能放在SamplerCollector类中,因为不会生效。所以才放到了Sampler::schedule函数这儿控制。

另外在echo_c++例子中使用下面两种方式看着都可以正确关闭:

  1. bvar::detail::FLAGS_bvar_enable_sampling = false;
  2. google::SetCommandLineOption("bvar_enable_sampling", "false");

我使用的是1.6.0版本,还是关闭不了。
image

@ghost
Copy link

ghost commented Dec 1, 2023

举个例子,如果我开启enable_rpcz,并且关闭bvar_enable_sampling,按照预期rpc_data目录不会记录span信息,文件也不会膨胀。

@ghost
Copy link

ghost commented Dec 1, 2023

image
看起了Sampler::schedule() 也在main函数之前运行了。所以这个FLAGS_bvar_enable_sampling 并控制不到sampling线程是否启动

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants