如何在更新简单计数器时阻止CouchDB创建文档修订 [英] How to prevent CouchDB to create document revisions when updating simple counters

查看:78
本文介绍了如何在更新简单计数器时阻止CouchDB创建文档修订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在CouchDB文档中存储计数器,在每个页面视图上递增。
CouchDB将仅为1次计数器更新创建此文档的完整版本。

I want to store counters in a CouchDB document, incremented on each page view. CouchDB will create a complete revision of this document for just 1 counter update.

这不会占用太多空间吗?
考虑到我每天有1M次点击,我可能会在一天内查看该文档的1M修订版。

Wouldn't this consume too much space? Considering that I have 1M hits in a day, I might be looking at 1M revisions to the document in a day.

对此有任何想法......

Any thoughts on this...

谢谢!

推荐答案

CouchDB对交易非常明确 - 它使得。在这种特殊情况下,我们正在谈论有一个防撞数据库,遗憾的是,在压缩之前可以并将使用大量磁盘。

CouchDB is very explicit about the trade-offs it makes. In this particular case, we are talking about having a crash proof database that, sadly, can and will use a lot of disk until compaction.

你可以获得这种可靠性和读取的并发性很高。您还可以与任何其他节点无缝复制。这是它的培根。由于碰撞计数器而必须紧凑是它的吮吸。忘了用_rev_limit来解决问题。你会搞砸自己,因为修订是Couch的基础。

You get with this reliability and a lot concurrency for reads. You will also get the ability to replicate seamlessly with any other nodes. This is the bacon of it. Having to compact because of bumped counters is the suck of it. Forget about mucking around with _rev_limit. You will screw yourself doing it because revisions are so foundational to Couch.

你有一种可能性就是记录一些信息,日期和时间,IP和其他东西。然后,您将创建一个发出所需数据的视图,并使用_count作为reduce函数。您将获得所需的信息以及其他一些可能有价值的分析内容。这是只是创建一个视图的解决方案。

One possibility that you have is logging some info, the date and time, IP's and other stuff. You'd then create a view emitting the data you need and using _count as your reduce function. You'll get the info you need and some other possibly valuable stuff for analytics. This is the "just create a view" solution.

第二种可能性是使用[redis]( http://redis.io/commands/incr )。 Redis相当不错,适合这个用例( http://ai.mee.nu/is_couchdb_the_anti -redis )。这将是正确工作的正确工具解决方案。

The second possibility would be using [redis] (http://redis.io/commands/incr). Redis is quite nice and would fit well with this use case (http://ai.mee.nu/is_couchdb_the_anti-redis). This would be the "the right tool for the right job" solution.

第三种可能性就是忽略它。它可能根本不是问题(如果你经常压缩)。这将是只是放松的解决方案。

The third possibility would be to simply ignore it. It might not be a problem at all (if you compact often). This would be the "just relax" solution.

你必须把好处带走,并确保优势超过劣势。在切割/优化之前测量所有内容两次。

You have to take the good with the bad and make sure the advantages outweighs the disadvantages. Measure everything twice before you cut/optimize.

这篇关于如何在更新简单计数器时阻止CouchDB创建文档修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆