Skip to content

Introduce a per-query memory limit #1375

Open

Description

@coffeemug

This came out of the team discussion. We should introduce a per-query-per-node memory limit configurable in run in MBs. If the query goes over the limit, it should be interrupted with an error.

Activity

  1. ghost assigned on Aug 28, 2013
  2. coffeemug commented on Aug 28, 2013

    @coffeemug
    ContributorAuthor

    This is somewhat related to #971.

  3. pixelspark commented on Aug 28, 2013

    @pixelspark

    A time limit would also be nice (see #1344)

  4. coffeemug commented on Aug 28, 2013

    @coffeemug
    ContributorAuthor

    @pixelspark -- cool idea. I think we already have a time limit, but it's hardcoded. It should be relatively easy to expose it. ("I think" is a key phrase here :))

  5. timmaxw commented on Aug 13, 2014

    @timmaxw
    Member

    Copying @mlucy's comment:

    I think we should just bite the bullet and do this. (We need it, or something similar but simpler, for #2721.)

  6. modified the milestones: subsequent, 1.15 on Aug 13, 2014
  7. timmaxw commented on Aug 13, 2014

    @timmaxw
    Member

    I think this is a good idea, but I think we should think carefully about the implementation or else it will end up being unmaintainable. This proposal would require making each datum_t be "owned" by a specific query. This is a big change; I suspect it's bigger than the configured_limits_t changes. We have to deal with all the same awkward cases, plus some new ones. For example, when we deserialize a datum through a mailbox_t, we want to apply the cost of that datum to the per-query memory limit for the query that initiated the request. It has the potential to get complicated quickly.

    Here are some thoughts:

    1. We should look at how other projects have implemented memory limits, and see if there are good ideas that we can copy.
    2. We should consider making the memory limit system generic instead of tying it to the concept of a ReQL queries. For example, we arguably want per-backfill memory limits. The other advantage of making the memory limit system generic is that we might want to thread it through weird places (such as mailboxes), and threading a ReQL-specific memory limit system through mailboxes is way uglier than threading a generic memory limit system through mailboxes.
    3. We should see if we can get away with implementing a datum_t size limit first. I'm pretty sure we'll want a per-query memory limit eventually, but implementing a datum_t size limit might buy us some time before it becomes critical, and we can use that time to do a better job.

    I also have some vague ideas for how a per-query memory limit system could work. I suggest that we create a base class for objects subject to the memory limit; this way, we can apply the memory limit gradually to one data type at a time in a controlled fashion. Subclasses of this base class would be constructed with a "memory account" object that they would use for allocations, and they would remember this object. We would overload "placement operator new" to use the special allocator. It would be possible to transfer ownership of a memory-managed object between two different accounts, or to construct it with no owner. (For example, mailboxes might construct objects received over with no owner, but then the query would take ownership once it received the object.) We would also provide a std allocator implementation that allocates from a memory account.

    Obviously this deserves a lot more thought than this brief paragraph, but these are just some ideas to get the juices flowing. Also, we shouldn't forget to check how other projects do it and see if there are existing best practices.

  8. mlucy commented on Aug 13, 2014

    @mlucy
    Member

    I would be OK with just having a per-{object/array} cumulative size limit and doing a generic memory-limiting system later. I think it depends on how hard it would be to limit memory on a per-query basis.

    (To be clear, when I say "cumulative size limit" I mean "An array of ten objects each with 5 fields counts as 50.")

    @gchpaco -- any opinion?

  9. modified the milestones: 1.15, 1.16 on Sep 4, 2014
  10. 28 remaining items

  11. modified the milestones: subsequent, on Dec 16, 2014
  12. modified the milestones: 2.1, subsequent on Mar 24, 2015
  13. modified the milestones: , 2.1 on Apr 17, 2015
  14. modified the milestones: subsequent, on Apr 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions