raw_template files duplication wastes DB space and memory

Bug #1570983 reported by Steven Hardy
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Heat
Fix Released
High
Crag Wolfe

Bug Description

I've been trying to better understand where our memory is used when creating large trees of stacks (such as a TripleO deployment which creates a tree of over 100 nested stacks).

I noticed one thing when profiling via heapy:

heap byvia=Partition of a set of 19392 objects. Total size = 19857584 bytes.
 Index Count % Size % Cumulative % Referred Via:
     0 9 0 2556360 13 2556360 13 "[u'file:/...ler.yaml']"
     1 9 0 2107872 11 4664232 23 "[u'file:/...map.yaml']"
     2 1 0 1779176 9 6443408 32 '.body'
     3 1 0 1530760 8 7974168 40 "[u'oslo.message']"
     4 5 0 1430408 7 9404576 47 '[27]'
     5 9 0 1098432 6 10503008 53 "[u'file:/...ute.yaml']"
     6 9 0 937008 5 11440016 58 "[u'file:/...oller.pp']"
     7 9 0 563256 3 12003272 60 "[u'file:/...age.yaml']"
     8 9 0 527904 3 12531176 63 "[u'file:/...age.yaml']"
     9 178 1 493640 2 13024816 66 '.func_doc', '[0]'

We're passing the files map to every single one of those 100+ nested stacks via RPC, which means we waste memory in the messages, and in the template.Template objects.

It also turns out to be a pretty big waste of DB space:

MariaDB [heat]> select sum(char_length(files))/1048576 from raw_template;
+---------------------------------+
| sum(char_length(files))/1048576 |
+---------------------------------+
| 461.9550 |
+---------------------------------+

So that's 461MB of data which is almost all duplicated (the files map is just over 300K and we're storing it over 100 times.

I think we probably need to create a new table which contains a record per file, then have a relationship between that table and the raw_template such that we can lazy-load the files on demand (each nested stack probably only requires access to a tiny subset of the global files map).

Tags: tripleo
Revision history for this message
Thomas Herve (therve) wrote :

I think that's meant to be addressed by https://review.openstack.org/#/c/303692/ ?

Steven Hardy (shardy)
tags: added: tripleo
Revision history for this message
Steven Hardy (shardy) wrote :

@therve - thanks I hadn't spotted that. Yeah it's tackling a similar problem, but I don't think it helps much with the RAM usage - I added some comments about how we might adjust things to avoid loading the entire files map/hash everywhere, feedback welcome on the ideas.

Changed in heat:
status: New → Triaged
Revision history for this message
Zane Bitter (zaneb) wrote :

It does help with RAM usage, because only one copy of each file is kept in RAM no matter how many stacks are referencing it.

Revision history for this message
Steven Hardy (shardy) wrote :

@zaneb: Ah thanks, yeah it was late and I missed the _d stuff making the hash global, so I guess we go from one files map per stack to one files map per engine worker, which is probably enough, it's still reduce the memory usage I've been measuring for TripleO by about a factor of ten (and obviously it's no longer proportional to the number of stacks).

Changed in heat:
assignee: nobody → Crag Wolfe (cwolfe)
importance: Undecided → High
milestone: none → newton-1
Changed in heat:
status: Triaged → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to heat (master)

Reviewed: https://review.openstack.org/303692
Committed: https://git.openstack.org/cgit/openstack/heat/commit/?id=fef94d0d7366576313883d9cfd59d775ea9e9907
Submitter: Jenkins
Branch: master

commit fef94d0d7366576313883d9cfd59d775ea9e9907
Author: Crag Wolfe <email address hidden>
Date: Sat Apr 9 02:51:45 2016 -0400

    De-duplicate raw_template.files

    Save space in the db by allowing templates (especially nested
    templates) to reference the same template files dictionary objects,
    now stored in the table raw_template_files. Also, cache template files
    per heat-engine process as a RAM/performance optimization.

    Also, begin to allow for future rolling upgrades with
    oslo.versionedobjects.

    Change-Id: I1842ea6ba6773a135b1007b793a5f0884417747d
    Closes-Bug: 1570983

Changed in heat:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/heat 7.0.0.0b1

This issue was fixed in the openstack/heat 7.0.0.0b1 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.