Skip to content

Performance improvements for metrics#5575

Merged
tramuntanal merged 6 commits intodevelopfrom
performance/metrics
Aug 12, 2020
Merged

Performance improvements for metrics#5575
tramuntanal merged 6 commits intodevelopfrom
performance/metrics

Conversation

@tramuntanal
Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal commented Dec 13, 2019

🎩 What? Why?

Metrics are extremely slow in Heroku, but execute correctly in dedicated servers.

Let's see if we can improve performance and avoid workers being killed.

📌 Related Issues

  • Related to #?
  • Fixes #?

📋 Subtasks

  • Add CHANGELOG entry
  • Add documentation regarding the feature
  • Add/modify seeds
  • Add tests
  • (memory and query) Retrieve component ids instead of whole objects.
    # replacing answers_metric_manage_spec.rbL18 for
    registry= nil
    report = MemoryProfiler.report do
          registry = generate_metric_registry
    end
    report.pretty_print
    # before
    Total allocated: 822737 bytes (8026 objects)
    Total retained:  67053 bytes (540 objects)
    # after
    Total allocated: 659112 bytes (6750 objects)
    Total retained:  21542 bytes (282 objects)
    
  • Review indexes

@stale
Copy link
Copy Markdown

stale bot commented Feb 11, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. @carolromero & @xabier feel free to chime in.

@stale stale bot added the wontfix label Feb 11, 2020
@stale stale bot closed this Feb 18, 2020
@tramuntanal
Copy link
Copy Markdown
Contributor Author

Keep open!

@tramuntanal tramuntanal reopened this Mar 3, 2020
@stale stale bot removed the wontfix label Mar 3, 2020
@tramuntanal tramuntanal changed the base branch from master to develop March 9, 2020 12:11
@tramuntanal tramuntanal force-pushed the performance/metrics branch from 16b75b8 to 55588de Compare July 24, 2020 08:04
@tramuntanal tramuntanal marked this pull request as ready for review July 30, 2020 07:20
@tramuntanal tramuntanal requested review from Leusev and ivan-mr July 31, 2020 07:45
ivan-mr
ivan-mr previously approved these changes Jul 31, 2020
Leusev
Leusev previously approved these changes Jul 31, 2020
Copy link
Copy Markdown
Contributor

@Leusev Leusev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good @tramuntanal

@andreslucena
Copy link
Copy Markdown
Member

Hi @Leusev @ivan-mr
Just to be clear how is the review process: have you guys tested this locally? Have you compared the memory usage before/after this branch?

Also, @tramuntanal, do you think that we need to start having performance testing to check for this kind of issue and especially for possible regressions in the future? (That could be developed on another issue to keep small the scope of this one)

@tramuntanal
Copy link
Copy Markdown
Contributor Author

Hi @andreslucena ,
I've deployed a backport of this branch to 0.21 to a Heroku staging env of ours with a dump of decidim-barcelona (which has thousands of participants) and, while running participants metrics, it reduces and stabilizes worker memory usage to around 750mb which is not ideal but is far better than having an always growing memory.

Although this problem was a design problem rather a bad performing query, performance testing would be great of course, not only for worker processes but for specially slow loading views. Probably not to be implemented up-front but as regression tests as you said.

I also plan to backport this PR to v0.22 so we can start testing it in real environments. Waiting for your approval in order to merge and backport

record.save!
end
@registry.each(&:save!)
@registry
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this is changing the API of the method (you were returning the list of records, now it's returning the list of cumulative), I don't know if this affects somewhere else down the line 😄

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it changes the returned value but it was used by tests (which are already refactored) but not by the background jobs, which rely on the persisted records. 👍

@andreslucena
Copy link
Copy Markdown
Member

I also plan to backport this PR to v0.22 so we can start testing it in real environments. Waiting for your approval in order to merge and backport

I can't review it but if you are confident that this improves what we already have is OK for me

@andreslucena
Copy link
Copy Markdown
Member

Hi @Leusev @ivan-mr
Just to be clear how is the review process: have you guys tested this locally? Have you compared the memory usage before/after this branch?

This question wasn't answered... Just to understand it, because I'm seeing lots of billed hours on PR reviews from @Leusev and @ivan-mr, but I actually don't see any comment from them in your PRs.

@Leusev
Copy link
Copy Markdown
Contributor

Leusev commented Aug 5, 2020

Hi @Leusev @ivan-mr
Just to be clear how is the review process: have you guys tested this locally? Have you compared the memory usage before/after this branch?

Hi @andreslucena
I'll try to explain review process in this case. Here, I just only reviewed modified files in PR.
I realised as the improvements followed the same pattern in all files.
In first place, I saw it was created a common visible_component_ids_from_spaces method in order to collect component ids instead of entire object to reduce memory consumption and increase speed.

  • decidim-core/app/queries/decidim/metric_manage.rb

After that, I checked that in almost all other files were replaced its own method's calls by this new one.

image

as well as was changed the way records are saved at the moment instead of being accumulated into an instance variable

image

Finally, I saw it was created a shared_example included/changed in _spec.rb's files in order to speed up testing too:

  • decidim-core/lib/decidim/core/test/shared_examples/metric_manage_shared_context.rb

image

In other hand, I also spoke with @tramuntanal and he explained me he tested it in on Heroku environment 'cause many records were needed and in order to have an environment as close to real as possible was needed too, so I accepted it.

Hope this is what you were asking for

@andreslucena
Copy link
Copy Markdown
Member

I'll try to explain review process in this case. Here, I just only reviewed modified files in PR.

Ok, thanks for the clarification!

@tramuntanal tramuntanal dismissed stale reviews from Leusev and ivan-mr via d763d9c August 12, 2020 08:55
@tramuntanal tramuntanal merged commit f92b6a5 into develop Aug 12, 2020
@tramuntanal tramuntanal deleted the performance/metrics branch August 12, 2020 10:37
Quentinchampenois pushed a commit to Quentinchampenois/decidim that referenced this pull request Aug 14, 2020
* Retrieve component ids instead of whole objects.

* Do not retain all metrics records in *MetricManage#save artifacts

* Make tests succeed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants