开发者

Storing DateTime in MongoDB effects on performance

We're having a discussion about storing dates in a MongoDB. I'm still pretty new to Mongo, so when I see the following in the documentation (http://api.mongodb.org/perl/MongoDB/DataTypes.html#Dates) I wonder:

Warning: creating DateTime objects is extremely slow. Consider saving dates as numbers and converting the numbers to DateTimes when needed. A single DateTime field can make deserialization开发者_运维知识库 up to 10 times slower.

If we're just storing them and having them come out with a query on the objects in the store, it's one thing, but it seems that if we're filtering or sorting on those fields it's another. The issue is the casting back and forth from a number to DateTime. Any thoughts on performance considerations are welcome. Thanks.


Internally both datetime and long are stored as 64 bit ints per bsonspec http://bsonspec.org/#/specification. So there not be an additional perf penalty due to the cast from a server perspective. the problem is with the slowness of DateTime in perl. Note: use datetime or long consistently as one will not match the other.


Mentioned elsewhere in this conversation, but it's worth summing up:

The performance issue in question is purely a Perl issue, and has to do with the cost of creating a DateTime object in Perl. It doesn't have anything to do with the performance of MongoDB in general, or MongoDB drivers for languages other than Perl. The C# driver should have no performance problems with DateTimes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜