优化 MONGO 中的数据类型 (c#)
我在这里阅读了关于 3 个不同数据库的基准测试:
http://blog.cubrid.org /dev-platform/nosql-benchmarking/
正如我所读,我看到MongoDB是“内存数据库”,所以如果DB的所有数据都可以 加载到RAM中DB的性能非常好。不然会很穷。 我读到 MongoDB 适合“没有大量数据”的项目。
我对我的第一个项目进行了调查,以优化每个文档。
我看到我的包含 BYTE 字段的文档将被 Mongo 转换为 Int32!
public partial class i_Room
{
[BsonId(IdGenerator = typeof(ObjectIdGenerator))]
public ObjectId _id { get; set; }
public global::System.Byte TypeRoom;
public global::System.Byte ModeRoom;
}
字段“TypeRoom”和“ModeRoom”在 MongoDB 中转换为 Int32:我使用 MongoVUE 来内省数据库数据。我认为这对记忆来说是非常危险的。
所以我的问题是:我需要做什么才能优化 Mongo 中的 BYTE 数据?
i have read this benchmark about 3 different database here:
http://blog.cubrid.org/dev-platform/nosql-benchmarking/
As i read, i see that MongoDB is "in memory database", so if all data of DB can be
loaded into RAM the performance of DB are very good. Otherwise will be very poor.
I read that MongoDB is good for project with "not amouth of data".
I have investigated on my first project in order to optimize every Document.
I see that my Document that have BYTE field will be converted in Int32 by Mongo!
public partial class i_Room
{
[BsonId(IdGenerator = typeof(ObjectIdGenerator))]
public ObjectId _id { get; set; }
public global::System.Byte TypeRoom;
public global::System.Byte ModeRoom;
}
The field "TypeRoom" and "ModeRoom" is converted in Int32 in MongoDB: i use MongoVUE in order to introspect the Database data. I think that this is very dangerous for memory.
So my question is: what i need to to in order to optimize BYTE data in Mongo?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除非您使用数十亿条记录,否则这不会造成太大伤害。 (int32 只有 4 个字节)
如果需要,您可以使用 bson 类型的二进制文件。这相当于 byte[]。
Except if you are using billions of records this won't hurt too much. (int32 is only 4 bytes)
You could instead use the bson type binary if you want. this is the equivalent of byte[].
由于 BSON 的二进制数据类型是可变长度的,并且还包含 1 字节的子类型字段,因此它的开销为 5 字节,因此将单个字节存储为二进制需要 6 字节。
最好将其存储为 4 字节整数。
Because BSON's binary data type is variable length and also includes a 1-byte subtype field, it has an overhead of 5 bytes, so storing a single byte as binary takes 6 bytes.
You are better off storing it as a 4-byte integer.