Impact of key length on performance and memory usage

985 views
Skip to first unread message

Raph

unread,
Nov 16, 2010, 10:03:37 AM11/16/10
to mongodb-user
Hello,

I have a Mongo database with a collection of 3000000 documents, each
filled with approximately 150 key-value pairs. These keys are the same
for all documents.

The keys are quite descriptive and around 15 characters long. Looking
at the database binary files, I understand that the key names are
repeated for every document and thus, uses a lot of disk space
(compared to the values, which are typically integers).

Would I see a performance increase if I use shorter keys?

My other problem is that I sometimes get "mmap failed with out of
memory" errors in the logs because the server runs out of memory.
Would reducing the storage size also improves this?

Thanks in advance.

Best Regards,
Raph

Kyle Banker

unread,
Nov 16, 2010, 10:48:25 AM11/16/10
to mongod...@googlegroups.com
In general, using smaller keys will use less memory and thus could
increase performance. Note that if you're going to alter your database
with smaller keys, you should rewrite the collections. Just performing
an update probably won't reclaim the greatest possible space.

> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

Nat

unread,
Nov 16, 2010, 10:49:43 AM11/16/10
to mongodb-user
yes, you will.
- shorter document reduces data size needed to send through network
- shorter document means more documents can be fit into one response
- shorter document definitely reduces memory usage on both client and
server side.

xneme

unread,
Nov 16, 2010, 2:57:09 PM11/16/10
to mongodb-user
vote this http://jira.mongodb.org/browse/SERVER-863

On 16 Lis, 16:48, Kyle Banker <k...@10gen.com> wrote:
> In general, using smaller keys will use less memory and thus could
> increase performance. Note that if you're going to alter your database
> with smaller keys, you should rewrite the collections. Just performing
> an update probably won't reclaim the greatest possible space.
>

Uri Goldstein

unread,
Mar 21, 2011, 5:51:20 AM3/21/11
to mongod...@googlegroups.com
Shorter documents through shorter key names have one major flaw - they make for bad code. Shorter names are harder to understand. Less understanding means more errors in code.

I think Mongo should separate performance from document key lengths. The jira issue that xneme mentioned is definitely worth looking into: http://jira.mongodb.org/browse/SERVER-863

Scott Hernandez

unread,
Mar 21, 2011, 8:54:40 AM3/21/11
to mongod...@googlegroups.com
There are many frameworks and tools that do this for you at the
application level; so that your code still uses the long and
meaningful names. It would be nice to see support at the server, but
it isn't stopping people from doing this now.

If you are getting errors on memory mapping files it would be good if
you can post the errors and state of your machine (preferably in
jira)? Sometimes these things can be fixed if they are bugs, and
sometimes you just need more resources.

Reply all
Reply to author
Forward
0 new messages