Is shortening MongoDB property names worthwhile?

前端 未结 5 496
名媛妹妹
名媛妹妹 2020-11-27 06:40

In Blog rolling with mongoDB, express and Node.js the author mentions it\'s a good idea to shorten property names:

....oft-reported issue with mongoDB

相关标签:
5条回答
  • 2020-11-27 07:06

    If using verbose xml, trying to ameliorate that with custom names could be very important. A user comment in the SERVER-863 ticket said in his case; I'm ' storing externally-defined XML objects, with verbose naming: the fieldnames are, perhaps, 70% of the total record size. So fieldname tokenization could be a giant win, both in terms of I/O and memory efficiency.'

    0 讨论(0)
  • 2020-11-27 07:11

    To quote Donald Knuth:

    Premature optimization is the root of all evil (or at least most of it) in programming.

    Build your application however seems most sensible, maintainable and logical. Then, if you have performance or storage issues, deal with those that have the greatest impact until either performance is satisfactory or the law of diminishing returns means there's no point in optimising further.

    If you are uncertain of the impact of particular design decisions (like long property names), create a prototype to test various hypotheses (like "will shorter property names save much space"). Don't expect the outcome of testing to be conclusive, however it may teach you things you didn't expect to learn.

    0 讨论(0)
  • 2020-11-27 07:16

    Adding my 2 cents on this..

    Long named attributes (or, "AbnormallyLongNameAttributes") can be avoided while designing the data model. In my previous organisation we tested keeping short named attributes strategy, such as, organisation defined 4-5 letter encoded strings, eg:

    1. First Name = FSTNM,
    2. Last Name = LSTNM,
    3. Monthly Profit Loss Percentage = MTPCT,
    4. Year on Year Sales Projection = YOYSP, and so on..)

    While we observed an improvement in query performance, largely due to the reduction in size of data being transferred over the network, or (since we used JAVA with MongoDB) the reduction in length of "keys" in MongoDB document/Java Map heap space, the overall improvement in performance was less than 15%.

    In my personal opinion, this was a micro-optimzation that came at an additional cost (and a huge headache) of maintaining/designing an additional system of managing Data Attribute Dictionary for each of the data models. This system was required to have an organisation wide transparency while debugging the application/answering to client queries.

    If you find yourself in a position where upto 20% increase in the performance with this strategy is lucrative to you, may be it is time to scale up your MongoDB servers/choose some other data modelling/querying strategy, or else to choose a different database altogether.

    0 讨论(0)
  • 2020-11-27 07:20

    Bottom line up: So keep it as compact as it still stays meaningful.

    I don't think that this is every truly required to be shortened to one letter names. Anyway you should shorten them as much as possible, and you feel comfortable with it. Lets say you have a users name: {FirstName, MiddleName, LastName} you may be good to go with even name:{first, middle, last}. If you feel comfortable you may be fine with name:{f, m,l}.
    You should use short names: As it will consume disk space, memory and thus may somewhat slowdown your application(less objects to hold in memory, slower lookup times due to bigger size and longer query time as seeking over data takes longer).
    A good schema documentation may tell the developer that t stands for town and not for title. Depending on your stack you may even be able to hide the developer from working with these short cuts through some helper utils to map it.

    Finally I would say that there's no guideline to when and how much you should shorten your schema names. It highly depends on your environment and requirements. But you're good to keep it compact if you can supply a good documentation explaining everything and/or offering utils to ease the life of developers and admins. Anyway admins are likely to interact directly with mongodb, so I guess a good documentation shouldn't be missed.

    0 讨论(0)
  • 2020-11-27 07:28

    Keep the priority for meaningful names above the priority for short names unless your own situation and testing provides a specific reason to alter those priorities.

    As mentioned in the comments of SERVER-863, if you're using MongoDB 3.0+ with the WiredTiger storage option with snappy compression enabled, long field names become even less of an issue as the compression effectively takes care of the shortening for you.

    0 讨论(0)
提交回复
热议问题