并发访问RRD(RRDTool)

发布于 2024-07-06 07:09:02 字数 515 浏览 6 评论 0原文

我使用 RRDTool (http://oss.oetiker.ch/rrdtool/) 作为图表用于存储性能指标的后端。 这是通过 RRDTool CLI 从 Python 脚本完成的。

我的问题是该脚本是多线程的,并且每个线程都以相当快的速度更新 RRD。 有时更新会失败,因为一个线程正在访问 RRD 文件,而另一个线程也尝试访问它。

我的印象是这是可以尝试的,因为 RRDTool 使用它自己的锁定机制,但我想事实并非如此。

有人有并发访问 RRD 的好方法吗?

我可以想到几种方法:

  1. 让 1 个线程创建一个队列,并且只从单个线程提供 RRD。

  2. 在 Python 脚本中创建我自己的锁定机制。 (我将如何做到这一点?)

有更好的办法吗?或者您以前遇到过这个问题吗?

I am using RRDTool (http://oss.oetiker.ch/rrdtool/) as a graphing back-end for storing performance metrics. This is done via the RRDTool CLI from a Python script.

My problem is that the script is multithreaded and each thread updates the RRD at a pretty rapid pace. Sometimes an update fails because one thread is accessing the RRD file while another one tries to access it also.

I was under the impression that this is OK to try since RRDTool uses its own locking mechanism, but I guess that isn't true.

Does anyone have a good approach for concurrent access to an RRD?

I can think of a few ways to go:

  1. have 1 thread create a queue and only feed the RRD from a single thread.

  2. create my own locking mechanism inside the Python script. (how would I do this?)

got anything better or have you run into this issue before?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

梦太阳 2024-07-13 07:09:02

您还可以尝试使用 rrdcached 进行更新。 然后所有的写更新都会通过rrdcached进行序列化。 当您想要读取 RRD 以生成图形时,您可以告诉守护进程刷新它,然后磁盘上的 RRD 将代表最新状态。

如果通过环境变量指向缓存的守护进程,所有 RRD 工具都将透明地执行此操作。

You could also try using rrdcached to do the updates. Then all write updates will be serialised through rrdcached. When you want to read the RRD to generate graphs you tell the daemon to flush it and the on-disk RRD will then represent the latest state.

All the RRD tools will do this transparently if pointed at the cached daemon via an environment variable.

情深如许 2024-07-13 07:09:02

rrd-users 列表中的此帖子可能会有用的。 rrdtool 的作者表示,它的文件锁定可以处理并发读写。

This thread in rrd-users list may be useful. The author of rrdtool states that its file locking handles concurrent reads and writes.

寒冷纷飞旳雪 2024-07-13 07:09:02

独占锁应该足以解决这个问题:

在主级别而不是线程级别定义锁定对象,并且您'重做。

在回复评论中进行编辑:

如果您在线程级别定义锁(lock = new Lock()),则每个正在运行的线程将有一个锁对象,并且您确实需要一个锁文件rrdtool更新,所以这个定义必须在主层。

An exclusive lock ought to be enough for this problem :

Define your lock object at the main level, not at the thread level, and you're done.

Edit in Response to comment :

if you define your lock (lock = new Lock()) at the thread level, you will have one lock object per running thread, and you really want a single lock for the file rrdtool updates, so this definition must be at the main level.

少女七分熟 2024-07-13 07:09:02

我建议使用rrdcached,这也将提高数据收集器的性能。 最新版本的rrdtool(1.4.x)极大地改进了rrdcached的功能和性能; 您也可以根据数据调整缓存行为以进行优化。

我们在这里大量使用 rrdcached,每秒对大量 RRD 文件进行数百次更新。

I would suggest using rrdcached, which will also improve the performance of your data collector. The latest versions of rrdtool (1.4.x) have greatly improved the functionality and performance of rrdcached; you can tune the caching behaviour according to your data to optimise, too.

We make heavy use of rrdcached here with several hundred updates per second over a large number of RRD files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文