简体   繁体   English

可以通过编程方式更新的系统全局计数器(在各种Linux版本上)?

[英]System-global counter that can be updated programmatically (on various Linux versions)?

I need some fast method to update key/value type data or alternatively an arbitrary amount of "counters" system-wide on Linux. 我需要一些快速的方法来更新键/值类型数据,或者在Linux上系统范围内更新任意数量的“计数器”。 The systems in question are Ubuntu 10.04, RHEL 4.8 and RHEL 5.x. 有问题的系统是Ubuntu 10.04,RHEL 4.8和RHEL5.x。

Now, I am aware of memcached, but it seems to be more suited for long-running processes, such as FastCGI processes. 现在,我知道了memcached,但它似乎更适合长时间运行的进程,例如FastCGI进程。 Unfortunately my process is a traditional CGI and therefore has to use some persistent storage outside of the process itself. 不幸的是,我的流程是传统的CGI,因此必须在流程本身之外使用一些持久性存储。

What options do I have and which are easiest and cheapest (wrt runtime) to access from C/C++? 我有哪些选项,哪些是从C / C ++访问最简单, 最便宜的 (wrt运行时)?

Note: this is not to measure the speed (ie performance counters) but to measure the number a certain type of event happens. 注意:这不是测量速度(即性能计数器),而是测量某种事件类型发生的次数。 And in order to count reliably, I need to be able to atomically increment the counters at will ... 为了可靠地进行计数,我需要能够随意增加计数器的数量...

You could try a small SQLite database. 您可以尝试使用小型SQLite数据库。 SQLite is FAST and reliable, any application can modify it and a transaction method prevents collision. SQLite是快速且可靠的,任何应用程序都可以对其进行修改,并且事务方法可以防止冲突。 Just add a record to a table for each event, or use a single table with an [event] column. 只需将记录添加到每个事件的表中,或将单个表与[event]列一起使用。 Inserting is really fast, what's slow is searching, but you'll only search when analysing the data, hopefully AFTER the performance is a factor. 插入确实非常快,但是搜索却很慢,但是只有在分析数据时才进行搜索,希望性能成为一个因素之后。

您可以使用简单的类似DBM的数据库,例如GDBM

Nowadays, in order 如今,为了

to update key/value type data 更新键/值类型数据

Developers often use NoSQL databases. 开发人员经常使用NoSQL数据库。 They run mainly on linux systems, and some of them are in C++ ( MongoDB & ClusterPoint ). 它们主要运行在linux系统上,其中一些使用C ++( MongoDBClusterPoint )。 They are really fast for this kind of things, they try really hard to keep low latency and it should be easy to access it from C++ since they are coded in C++. 它们在这种情况下确实非常快,它们尽力保持低延迟,并且由于它们是用C ++编码的,因此应该很容易从C ++访问它。

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

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