Skip to content

The OHM website is under heavy load (queue full) #850

Closed

Description

@Rub21

Users have been reported many times that the website is under heavy load, and sometimes the website just stops working #783 (comment)

image image

Since we already fixed the cgimap issue in the ticket: #783, I am opening this ticket to focus on the heavy workloads on the website.

Activity

  1. Rub21 commented on Jul 18, 2024

    @Rub21
    MemberAuthor

    Conducting an evaluation of the containers regarding the high usage:

    • Website memory/cpu usage:
    image
    • Database memory/cpu usage:
    image

    There is a high usage of resources at ~ 05:32 UTC, and only user jeffmeyer has been uploading large changesets to the website.

    image
  2. Rub21 commented on Jul 18, 2024

    @Rub21
    MemberAuthor

    This issue could be due to the proxy timeout, but currently, Ingress is configured to support 20 minutes of proxy and 200MB of data transfer https://github.com/developmentseed/osm-seed/blob/develop/osm-seed/templates/web/web-ingress.yaml#L7-L12 . I’ve just opened a PR that updates the proxy timeout values to 20 minutes in the Apache config: OpenHistoricalMap/ohm-deploy#347

  3. Rub21 commented on Jul 18, 2024

    @Rub21
    MemberAuthor

    Also, for more clarification about the resource usage for each web API container, here is the configuration: https://github.com/OpenHistoricalMap/ohm-deploy/blob/main/values.production.template.yaml#L150-L157

        resources:
          enabled: true
          requests:
            memory: "3Gi"
            cpu: "2"
          limits:
            memory: "3Gi"
            cpu: "2"

    Comparing what is shown in the Prometheus stats, none of the containers are hitting the maximum values of the resources. Maybe something else is going on, or some configuration still needs to be fixed to use the resources of the containers to their maximum potential.
    cc. @batpad

  4. self-assigned this
    on Jul 18, 2024
  5. jeffreyameyer commented on Jul 18, 2024

    @jeffreyameyer
    Member

    As a user, without supporting data, it "feels" like the relation query fix is still a problem.

    Uploads are very zippy for when ways and nodes are getting uploaded.

    Relations still bog down the upload process. This was not the case briefly recently, while we applied fixes from mmd & bitner, but it seems these issues have reappeared. It's almost like an A/B/A test the difference is so clear.

  6. Rub21 commented on Jul 18, 2024

    @Rub21
    MemberAuthor

    hey @mmd-osm, could you help us with other question? . Yesterday, I set the following values in OHM database:

    set enable_mergejoin=false;
    set enable_hashjoin=false;
    SELECT pg_reload_conf();

    It seems it only applies for the session where i was, not for the whole database. because i see the values today and show enable_mergejoin=on.

    I read that to apply these values to the whole database, we need to set them up in the postgresql.conf file. do you apply the settings for the hole OSM database?

    cc @batpad

  7. mmd-osm commented on Jul 18, 2024

    @mmd-osm

    The code to disable merge and hash joins in CGImap changes the current session only (this was done for the /map endpoint, it does not change the upload behavior). I just checked the OSM chef repo, and don't find these settings on a global level: https://github.com/openstreetmap/chef/blob/master/cookbooks/postgresql/templates/default/postgresql.conf.erb

    Changing the setting on a global level needs more testing, since it might impact other unrelated queries, which were doing fine previously.

  8. Rub21 commented on Jul 19, 2024

    @Rub21
    MemberAuthor

    @mmd-osm I was investigating how to enable the set enable_mergejoin=false; only for the CGImap process. I did something like this : https://github.com/OpenHistoricalMap/ohm-deploy/blob/main/images/web/cgimap.sh#L30-L32 It did not work, also I did not find documentation on how to enable it. Is it some ENV var that runs this? , Also, since it is in the CGImap code, should those lines be enabled automatically, or at which step will these lines be executed?

  9. mmd-osm commented on Jul 20, 2024

    @mmd-osm

    Since CGImap uses libpqxx which in turn uses libpq, this should work. I double checked if PGOPTIONS is taken into account when running in CGImap in daemon mode, and defined a statement timeout of 1s. This should kick in for bigger ways/relations updates, and that's exactly what I've seen in the log files below.

    export PGOPTIONS="-c statement_timeout=1000ms -c lc_messages=en_US.UTF-8"
    
    [2024-07-20T07:57:10 #31491] Started request for changeset/upload 128245 from 127.0.0.1
    [2024-07-20T07:57:10 #31491] Executed prepared statement changeset_exists in 0 ms, returning 1 rows, 1 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement changeset_current_lock in 0 ms, returning 1 rows, 1 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement insert_tmp_create_nodes in 12 ms, returning 3110 rows, 3110 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement lock_current_nodes in 6 ms, returning 3110 rows, 3110 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement current_nodes_to_history in 38 ms, returning 0 rows, 3110 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement calc_node_bbox in 6 ms, returning 1 rows, 1 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement insert_tmp_create_ways in 6 ms, returning 2201 rows, 2201 affected rows
    [2024-07-20T07:57:10 #31491] Executed prepared statement lock_current_ways in 3 ms, returning 2201 rows, 2201 affected rows
    [2024-07-20T07:57:11 #31491] Executed prepared statement lock_future_nodes_in_ways in 478 ms, returning 233110 rows, 233110 affected rows
    [2024-07-20T07:57:11 #31491] Executed prepared statement insert_new_current_way_tags in 253 ms, returning 0 rows, 29203 affected rows
    [2024-07-20T07:57:12 #31491] Returning with http error 500 with reason ERROR:  canceling statement due to statement timeout
    CONTEXT:  SQL statement "SELECT 1 FROM ONLY "public"."current_ways" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x"
    
    [2024-07-20T07:57:12 #31491] ERROR:  canceling statement due to statement timeout
    CONTEXT:  SQL statement "SELECT 1 FROM ONLY "public"."current_ways" x WHERE "id" OPERATOR(pg_catalog.=) $1 FOR KEY SHARE OF x"
    
    [2024-07-20T07:57:12 #31487] Executed prepared statement oauth2_access_token in 1 ms, returning 1 rows, 1 affected rows
    
    

    You could also add auto explain to your postgresql.conf and later evaluate slow queries in /var/log/postgresql/postgresql-xx-main.log logfile.

    session_preload_libraries = 'auto_explain'
    auto_explain.log_min_duration = '3s'
    
    

    Settings: https://www.postgresql.org/docs/current/runtime-config-query.html

    Both enable_seqscan=off and jit=off might be interesting

  10. added
    infrastructure
    API
    on Jul 22, 2024
  11. jeffreyameyer commented on Jul 22, 2024

    @jeffreyameyer
    Member

    @Rub21 - please let me know when this is done and the site is ready for another test. I am eager to get this one closed. : )

  12. jeffreyameyer commented on Jul 25, 2024

    @jeffreyameyer
    Member

    @Rub21 - I just did a large upload on staging that seemed to work quite well... unless it is what brought down staging. The upload portion worked quite well before the site went down. Please let me know when you're ready for me to try again.

  13. Rub21 commented on Jul 25, 2024

    @Rub21
    MemberAuthor

    @mmd-osm I have libpqxx-dev as dependencies https://github.com/OpenHistoricalMap/ohm-deploy/blob/main/images/web/Dockerfile#L28, but still it did not take the PGOPTIONS export PGOPTIONS="-c enable_mergejoin=false -c enable_hashjoin=false"

    I am testing it using the follow query:

      SELECT 
      pid,
      usename,
      application_name,
      client_addr,
      backend_start,
      state,
      state_change,
      query,
      current_setting('enable_mergejoin', true) AS enable_mergejoin,
      current_setting('enable_hashjoin', true) AS enable_hashjoin
    FROM 
      pg_stat_activity;
    image
  14. Rub21 commented on Jul 25, 2024

    @Rub21
    MemberAuthor

    i tested the timeout in the PGOPTIONS, seems it works because of the logs returns 👇

    
    [2024-07-25T19:34:28 #11379] Preparing OAuth prepared statements.
    [2024-07-25T19:34:28 #11379] Initialised
    [2024-07-25T19:34:41 #1281] Executed prepared statement get_user_id_pass in 1 ms, returning 1 rows, 1 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement roles_for_user in 0 ms, returning 0 rows, 0 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement check_user_blocked in 0 ms, returning 0 rows, 0 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement is_user_active in 0 ms, returning 1 rows, 1 affected rows
    [2024-07-25T19:34:41 #1281] Started request for changeset/upload 118505 from 10.10.40.81
    [2024-07-25T19:34:41 #1281] Executed prepared statement changeset_exists in 0 ms, returning 1 rows, 1 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement changeset_current_lock in 0 ms, returning 1 rows, 1 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement insert_tmp_create_nodes in 18 ms, returning 3110 rows, 3110 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement lock_current_nodes in 9 ms, returning 3110 rows, 3110 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement current_nodes_to_history in 61 ms, returning 0 rows, 3110 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement current_node_tags_to_history in 11 ms, returning 0 rows, 0 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement calc_node_bbox in 9 ms, returning 1 rows, 1 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement insert_tmp_create_ways in 10 ms, returning 2201 rows, 2201 affected rows
    [2024-07-25T19:34:41 #1281] Executed prepared statement lock_current_ways in 6 ms, returning 2201 rows, 2201 affected rows
    [2024-07-25T19:34:42 #1281] Executed prepared statement lock_future_nodes_in_ways in 848 ms, returning 233110 rows, 233110 affected rows
    [2024-07-25T19:34:42 #1281] Executed prepared statement insert_new_current_way_tags in 391 ms, returning 0 rows, 29203 affected rows
    [2024-07-25T19:34:43 #1281] Returning with http error 500 with reason ERROR:  canceling statement due to statement timeout
    
    [2024-07-25T19:34:43 #1281] ERROR:  canceling statement due to statement timeout
    
    [2024-07-25T19:34:44 #11512] Preparing OAuth prepared statements.
    [2024-07-25T19:34:44 #11512] Initialised
    
    
  15. mmd-osm commented on Jul 25, 2024

    @mmd-osm

    Ok, this looks better. I was struggling a bit to make some sense of the SELECT * FROM pg_stat_activity query. I think what you see there in columns enable_mergejoin + enable_hashjoin depends on the database connection you were using to run that query in some admin tool. It doesn't represent the settings that were in place when CGImap executed the query.

  16. jeffreyameyer commented on Jul 26, 2024

    @jeffreyameyer
    Member

    Who - just uploaded a lot of data changesets 131797 - 131809. Looks like everything went just fine, which is much different from before.

    I'd be interested if the logs show anything unusual, both for query and writes, etc., as well as CPU loads.

  17. Rub21 commented on Jul 26, 2024

    @Rub21
    MemberAuthor

    Following Jeff’s comments and my testing, the large changeset uploads are now working efficiently and take less than a minute to complete. This issue was challenging, but I gained valuable experience managing Postgres. PGOPTIONS works fine in cgimap, but it was necessary to clean and update the table statistics to make enable_mergejoin and enable_hashjoin effective. Running the following queries improved update times significantly, reducing changeset processing from 15 minutes to 0.18 minutes. For future migrations, it’s recommended to run these commands.

    VACUUM ANALYZE current_nodes;
    VACUUM ANALYZE current_way_nodes;
    VACUUM ANALYZE current_ways;
    VACUUM ANALYZE current_relations;
    VACUUM ANALYZE current_relation_members;

    Huge thanks to @mmd-osm for your support on this issue.

    cc. @batpad @danrademacher

  18. Rub21 commented on Jul 31, 2024

    @Rub21
    MemberAuthor

    Closing this ticket, the issue has been resolved.

  19. danrademacher commented on Jul 31, 2024

    @danrademacher

    Awesome work!

  20. added theissue type on Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

APIinfrastructure

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions