summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Hodgson <matthew@matrix.org>2018-01-09 16:25:04 +0000
committerhera <matrix@template.upcloud.com>2018-01-09 17:52:36 +0000
commit2cb082352b1816f7f7eeb308fb95b33f3fc2c508 (patch)
treeee02942d1441abb3f98144e1f605b6bd77920bd7
parentMerge branch 'develop' of github.com:matrix-org/synapse into matrix-org-hotfixes (diff)
downloadsynapse-2cb082352b1816f7f7eeb308fb95b33f3fc2c508.tar.xz
avoid 80s GIN inserts by tweaking work_mem
see https://github.com/matrix-org/synapse/issues/2753 for details
-rw-r--r--synapse/storage/search.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/synapse/storage/search.py b/synapse/storage/search.py
index 3a6c4c7570..f77b09018a 100644
--- a/synapse/storage/search.py
+++ b/synapse/storage/search.py
@@ -106,6 +106,7 @@ class SearchStore(BackgroundUpdateStore):
                 event_search_rows.append((event_id, room_id, key, value))
 
             if isinstance(self.database_engine, PostgresEngine):
+                txn.execute("SET work_mem='256KB'")
                 sql = (
                     "INSERT INTO event_search (event_id, room_id, key, vector)"
                     " VALUES (?,?,?,to_tsvector('english', ?))"
@@ -123,6 +124,9 @@ class SearchStore(BackgroundUpdateStore):
                 clump = event_search_rows[index:index + INSERT_CLUMP_SIZE]
                 txn.executemany(sql, clump)
 
+            if isinstance(self.database_engine, PostgresEngine):
+                txn.execute("RESET work_mem")
+
             progress = {
                 "target_min_stream_id_inclusive": target_min_stream_id,
                 "max_stream_id_exclusive": min_stream_id,