Slow homepage (SLOW_GET_HELPER)

  • What’s your URL? Hosted on an internal network
  • What version of Ghost are you using? 5.22.9

And

  • How was Ghost installed and configured?
    Manually on a server using ghost-cli

  • What Node version, database, OS & browser are you using?
    Node 16, MySQL 8.0.29, CentOS 7, Chrome

  • What errors or information do you see in the console?

{{#get}} helper took 1639ms to complete
Error ID:
    cc8573e0-5f6f-11ed-a38b-4b36a148a93b
Error Code:
    SLOW_GET_HELPER
Details:
    api:          postsPublic.browse
    apiOptions:
      include: authors
      limit:   all
      context:
        member: null
    returnedRows: 335

[2022-11-08 14:38:39] INFO "GET /" 200 1714ms
  • What steps could someone else take to reproduce the issue you’re having?
    Load homepage

The homepage takes about 2 seconds to load.
Looking at the slow query log in MySQL, I can see the following entries when loading the homepage

# Time: 2022-11-08T14:38:39.224304Z
# User@Host: gh[gh] @  [<ip redacted>]  Id: 103554947
# Query_time: 0.190285  Lock_time: 0.000001 Rows_sent: 335  Rows_examined: 694
SET timestamp=1667918319;
select `posts`.* from `posts` where (`posts`.`status` = 'published' and `posts`.`type` = 'post') order by CASE WHEN posts.status = 'scheduled' THEN 1 WHEN posts.status = 'draft' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != 'draft' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC;
# Time: 2022-11-08T14:38:39.324790Z
# User@Host: gh[gh] @  [<ip redacted>]  Id: 103553719
# Query_time: 0.290404  Lock_time: 0.000001 Rows_sent: 33  Rows_examined: 392
SET timestamp=1667918319;
select `posts`.* from `posts` where (`posts`.`status` = 'published' and (`posts`.`featured` = true and `posts`.`type` = 'post')) order by `posts`.`published_at` DESC;
# Time: 2022-11-08T14:38:39.546656Z
# User@Host: gh[gh] @  [<ip redacted>1]  Id: 103552862
# Query_time: 0.512487  Lock_time: 0.000001 Rows_sent: 335  Rows_examined: 694
SET timestamp=1667918319;
select `posts`.* from `posts` where (`posts`.`status` = 'published' and `posts`.`type` = 'post') order by CASE WHEN posts.status = 'scheduled' THEN 1 WHEN posts.status = 'draft' THEN 2 ELSE 3 END ASC,CASE WHEN posts.status != 'draft' THEN posts.published_at END DESC,posts.updated_at DESC,posts.id DESC;

There’s not too many posts, so it sounds odd it’s so slow.
Running the queries manually against the MySQL server is fast (0.02s). It’s just when Ghost runs them, they’re slow.

There is virtually no load on the server. MySQL runs on the same server.

Any ideas what could be going on here? Maybe they’re run in a transaction and this causes some kind of issues?

I’m happy to provide more debugging information if needed.

It looks like you’re making use of a {{#get}} helper in your theme, which is fetching 335 authors, and that takes 1.6s to complete. Is this expected?

The get helper is fetching 335 full posts with author records added to each. If you’re not doing something with all 335 posts you should add a limit param and potentially a fields param so you’re only working with data that you’re displaying.

2 Likes

This was very helpful, thank you for taking the time.