workers.html 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. <!DOCTYPE HTML>
  2. <html lang="en" class="sidebar-visible no-js light">
  3. <head>
  4. <!-- Book generated using mdBook -->
  5. <meta charset="UTF-8">
  6. <title>Workers - Synapse</title>
  7. <!-- Custom HTML head -->
  8. <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  9. <meta name="description" content="">
  10. <meta name="viewport" content="width=device-width, initial-scale=1">
  11. <meta name="theme-color" content="#ffffff" />
  12. <link rel="icon" href="favicon.svg">
  13. <link rel="shortcut icon" href="favicon.png">
  14. <link rel="stylesheet" href="css/variables.css">
  15. <link rel="stylesheet" href="css/general.css">
  16. <link rel="stylesheet" href="css/chrome.css">
  17. <link rel="stylesheet" href="css/print.css" media="print">
  18. <!-- Fonts -->
  19. <link rel="stylesheet" href="FontAwesome/css/font-awesome.css">
  20. <link rel="stylesheet" href="fonts/fonts.css">
  21. <!-- Highlight.js Stylesheets -->
  22. <link rel="stylesheet" href="highlight.css">
  23. <link rel="stylesheet" href="tomorrow-night.css">
  24. <link rel="stylesheet" href="ayu-highlight.css">
  25. <!-- Custom theme stylesheets -->
  26. <link rel="stylesheet" href="docs/website_files/table-of-contents.css">
  27. <link rel="stylesheet" href="docs/website_files/remove-nav-buttons.css">
  28. <link rel="stylesheet" href="docs/website_files/indent-section-headers.css">
  29. </head>
  30. <body>
  31. <!-- Provide site root to javascript -->
  32. <script type="text/javascript">
  33. var path_to_root = "";
  34. var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "navy" : "light";
  35. </script>
  36. <!-- Work around some values being stored in localStorage wrapped in quotes -->
  37. <script type="text/javascript">
  38. try {
  39. var theme = localStorage.getItem('mdbook-theme');
  40. var sidebar = localStorage.getItem('mdbook-sidebar');
  41. if (theme.startsWith('"') && theme.endsWith('"')) {
  42. localStorage.setItem('mdbook-theme', theme.slice(1, theme.length - 1));
  43. }
  44. if (sidebar.startsWith('"') && sidebar.endsWith('"')) {
  45. localStorage.setItem('mdbook-sidebar', sidebar.slice(1, sidebar.length - 1));
  46. }
  47. } catch (e) { }
  48. </script>
  49. <!-- Set the theme before any content is loaded, prevents flash -->
  50. <script type="text/javascript">
  51. var theme;
  52. try { theme = localStorage.getItem('mdbook-theme'); } catch(e) { }
  53. if (theme === null || theme === undefined) { theme = default_theme; }
  54. var html = document.querySelector('html');
  55. html.classList.remove('no-js')
  56. html.classList.remove('light')
  57. html.classList.add(theme);
  58. html.classList.add('js');
  59. </script>
  60. <!-- Hide / unhide sidebar before it is displayed -->
  61. <script type="text/javascript">
  62. var html = document.querySelector('html');
  63. var sidebar = 'hidden';
  64. if (document.body.clientWidth >= 1080) {
  65. try { sidebar = localStorage.getItem('mdbook-sidebar'); } catch(e) { }
  66. sidebar = sidebar || 'visible';
  67. }
  68. html.classList.remove('sidebar-visible');
  69. html.classList.add("sidebar-" + sidebar);
  70. </script>
  71. <nav id="sidebar" class="sidebar" aria-label="Table of contents">
  72. <div class="sidebar-scrollbox">
  73. <ol class="chapter"><li class="chapter-item expanded affix "><li class="part-title">Introduction</li><li class="chapter-item expanded "><a href="welcome_and_overview.html">Welcome and Overview</a></li><li class="chapter-item expanded affix "><li class="part-title">Setup</li><li class="chapter-item expanded "><a href="setup/installation.html">Installation</a></li><li class="chapter-item expanded "><a href="postgres.html">Using Postgres</a></li><li class="chapter-item expanded "><a href="reverse_proxy.html">Configuring a Reverse Proxy</a></li><li class="chapter-item expanded "><a href="setup/forward_proxy.html">Configuring a Forward/Outbound Proxy</a></li><li class="chapter-item expanded "><a href="turn-howto.html">Configuring a Turn Server</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="setup/turn/coturn.html">coturn TURN server</a></li><li class="chapter-item expanded "><a href="setup/turn/eturnal.html">eturnal TURN server</a></li></ol></li><li class="chapter-item expanded "><a href="delegate.html">Delegation</a></li><li class="chapter-item expanded affix "><li class="part-title">Upgrading</li><li class="chapter-item expanded "><a href="upgrade.html">Upgrading between Synapse Versions</a></li><li class="chapter-item expanded affix "><li class="part-title">Usage</li><li class="chapter-item expanded "><a href="federate.html">Federation</a></li><li class="chapter-item expanded "><a href="usage/configuration/index.html">Configuration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/config_documentation.html">Configuration Manual</a></li><li class="chapter-item expanded "><a href="usage/configuration/homeserver_sample_config.html">Homeserver Sample Config File</a></li><li class="chapter-item expanded "><a href="usage/configuration/logging_sample_config.html">Logging Sample Config File</a></li><li class="chapter-item expanded "><a href="structured_logging.html">Structured Logging</a></li><li class="chapter-item expanded "><a href="templates.html">Templates</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/index.html">User Authentication</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/index.html">Single-Sign On</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="openid.html">OpenID Connect</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/single_sign_on/cas.html">CAS</a></li><li class="chapter-item expanded "><a href="sso_mapping_providers.html">SSO Mapping Providers</a></li></ol></li><li class="chapter-item expanded "><a href="password_auth_providers.html">Password Auth Providers</a></li><li class="chapter-item expanded "><a href="jwt.html">JSON Web Tokens</a></li><li class="chapter-item expanded "><a href="usage/configuration/user_authentication/refresh_tokens.html">Refresh Tokens</a></li></ol></li><li class="chapter-item expanded "><a href="CAPTCHA_SETUP.html">Registration Captcha</a></li><li class="chapter-item expanded "><a href="application_services.html">Application Services</a></li><li class="chapter-item expanded "><a href="server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="consent_tracking.html">Consent Tracking</a></li><li class="chapter-item expanded "><a href="user_directory.html">User Directory</a></li><li class="chapter-item expanded "><a href="message_retention_policies.html">Message Retention Policies</a></li><li class="chapter-item expanded "><a href="modules/index.html">Pluggable Modules</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/writing_a_module.html">Writing a module</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="modules/spam_checker_callbacks.html">Spam checker callbacks</a></li><li class="chapter-item expanded "><a href="modules/third_party_rules_callbacks.html">Third-party rules callbacks</a></li><li class="chapter-item expanded "><a href="modules/presence_router_callbacks.html">Presence router callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_validity_callbacks.html">Account validity callbacks</a></li><li class="chapter-item expanded "><a href="modules/password_auth_provider_callbacks.html">Password auth provider callbacks</a></li><li class="chapter-item expanded "><a href="modules/background_update_controller_callbacks.html">Background update controller callbacks</a></li><li class="chapter-item expanded "><a href="modules/account_data_callbacks.html">Account data callbacks</a></li><li class="chapter-item expanded "><a href="modules/porting_legacy_module.html">Porting a legacy module to the new interface</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="workers.html" class="active">Workers</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="synctl_workers.html">Using synctl with Workers</a></li><li class="chapter-item expanded "><a href="systemd-with-workers/index.html">Systemd</a></li></ol></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/index.html">Administration</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/admin_api/index.html">Admin API</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="admin_api/account_validity.html">Account Validity</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/background_updates.html">Background Updates</a></li><li class="chapter-item expanded "><a href="admin_api/event_reports.html">Event Reports</a></li><li class="chapter-item expanded "><a href="admin_api/media_admin_api.html">Media</a></li><li class="chapter-item expanded "><a href="admin_api/purge_history_api.html">Purge History</a></li><li class="chapter-item expanded "><a href="admin_api/register_api.html">Register Users</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/registration_tokens.html">Registration Tokens</a></li><li class="chapter-item expanded "><a href="admin_api/room_membership.html">Manipulate Room Membership</a></li><li class="chapter-item expanded "><a href="admin_api/rooms.html">Rooms</a></li><li class="chapter-item expanded "><a href="admin_api/server_notices.html">Server Notices</a></li><li class="chapter-item expanded "><a href="admin_api/statistics.html">Statistics</a></li><li class="chapter-item expanded "><a href="admin_api/user_admin_api.html">Users</a></li><li class="chapter-item expanded "><a href="admin_api/version_api.html">Server Version</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_api/federation.html">Federation</a></li></ol></li><li class="chapter-item expanded "><a href="manhole.html">Manhole</a></li><li class="chapter-item expanded "><a href="metrics-howto.html">Monitoring</a></li><li><ol class="section"><li class="chapter-item expanded "><a href="usage/administration/monitoring/reporting_homeserver_usage_statistics.html">Reporting Homeserver Usage Statistics</a></li></ol></li><li class="chapter-item expanded "><a href="usage/administration/monthly_active_users.html">Monthly Active Users</a></li><li class="chapter-item expanded "><a href="usage/administration/understanding_synapse_through_grafana_graphs.html">Understanding Synapse Through Grafana Graphs</a></li><li class="chapter-item expanded "><a href="usage/administration/useful_sql_for_admins.html">Useful SQL for Admins</a></li><li class="chapter-item expanded "><a href="usage/administration/database_maintenance_tools.html">Database Maintenance Tools</a></li><li class="chapter-item expanded "><a href="usage/administration/state_groups.html">State Groups</a></li><li class="chapter-item expanded "><a href="usage/administration/request_log.html">Request log format</a></li><li class="chapter-item expanded "><a href="usage/administration/admin_faq.html">Admin FAQ</a></li><li class="chapter-item expanded "><div>Scripts</div></li></ol></li><li class="chapter-item expanded "><li class="part-title">Development</li><li class="chapter-item expanded "><a href="development/contributing_guide.html">Contributing Guide</a></li><li class="chapter-item expanded "><a href="code_style.html">Code Style</a></li><li class="chapter-item expanded "><a href="development/reviews.html">Reviewing Code</a></li><li class="chapter-item expanded "><a href="development/releases.html">Release Cycle</a></li><li class="chapter-item expanded "><a href="development/git.html">Git Usage</a></li><li class="chapter-item expanded "><div>Testing</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/demo.html">Demo scripts</a></li></ol></li><li class="chapter-item expanded "><a href="opentracing.html">OpenTracing</a></li><li class="chapter-item expanded "><a href="development/database_schema.html">Database Schemas</a></li><li class="chapter-item expanded "><a href="development/experimental_features.html">Experimental features</a></li><li class="chapter-item expanded "><a href="development/dependencies.html">Dependency management</a></li><li class="chapter-item expanded "><div>Synapse Architecture</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/synapse_architecture/cancellation.html">Cancellation</a></li><li class="chapter-item expanded "><a href="log_contexts.html">Log Contexts</a></li><li class="chapter-item expanded "><a href="replication.html">Replication</a></li><li class="chapter-item expanded "><a href="tcp_replication.html">TCP Replication</a></li><li class="chapter-item expanded "><a href="development/synapse_architecture/faster_joins.html">Faster remote joins</a></li></ol></li><li class="chapter-item expanded "><a href="development/internal_documentation/index.html">Internal Documentation</a></li><li><ol class="section"><li class="chapter-item expanded "><div>Single Sign-On</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="development/saml.html">SAML</a></li><li class="chapter-item expanded "><a href="development/cas.html">CAS</a></li></ol></li><li class="chapter-item expanded "><a href="development/room-dag-concepts.html">Room DAG concepts</a></li><li class="chapter-item expanded "><div>State Resolution</div></li><li><ol class="section"><li class="chapter-item expanded "><a href="auth_chain_difference_algorithm.html">The Auth Chain Difference Algorithm</a></li></ol></li><li class="chapter-item expanded "><a href="media_repository.html">Media Repository</a></li><li class="chapter-item expanded "><a href="room_and_user_statistics.html">Room and User Statistics</a></li></ol></li><li class="chapter-item expanded "><div>Scripts</div></li><li class="chapter-item expanded affix "><li class="part-title">Other</li><li class="chapter-item expanded "><a href="deprecation_policy.html">Dependency Deprecation Policy</a></li><li class="chapter-item expanded "><a href="other/running_synapse_on_single_board_computers.html">Running Synapse on a Single-Board Computer</a></li></ol>
  74. </div>
  75. <div id="sidebar-resize-handle" class="sidebar-resize-handle"></div>
  76. </nav>
  77. <div id="page-wrapper" class="page-wrapper">
  78. <div class="page">
  79. <div id="menu-bar-hover-placeholder"></div>
  80. <div id="menu-bar" class="menu-bar sticky bordered">
  81. <div class="left-buttons">
  82. <button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
  83. <i class="fa fa-bars"></i>
  84. </button>
  85. <button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
  86. <i class="fa fa-paint-brush"></i>
  87. </button>
  88. <ul id="theme-list" class="theme-popup" aria-label="Themes" role="menu">
  89. <li role="none"><button role="menuitem" class="theme" id="light">Light (default)</button></li>
  90. <li role="none"><button role="menuitem" class="theme" id="rust">Rust</button></li>
  91. <li role="none"><button role="menuitem" class="theme" id="coal">Coal</button></li>
  92. <li role="none"><button role="menuitem" class="theme" id="navy">Navy</button></li>
  93. <li role="none"><button role="menuitem" class="theme" id="ayu">Ayu</button></li>
  94. </ul>
  95. <button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
  96. <i class="fa fa-search"></i>
  97. </button>
  98. </div>
  99. <h1 class="menu-title">Synapse</h1>
  100. <div class="right-buttons">
  101. <a href="print.html" title="Print this book" aria-label="Print this book">
  102. <i id="print-button" class="fa fa-print"></i>
  103. </a>
  104. <a href="https://github.com/matrix-org/synapse" title="Git repository" aria-label="Git repository">
  105. <i id="git-repository-button" class="fa fa-github"></i>
  106. </a>
  107. <a href="https://github.com/matrix-org/synapse/edit/develop/docs/workers.md" title="Suggest an edit" aria-label="Suggest an edit">
  108. <i id="git-edit-button" class="fa fa-edit"></i>
  109. </a>
  110. </div>
  111. </div>
  112. <div id="search-wrapper" class="hidden">
  113. <form id="searchbar-outer" class="searchbar-outer">
  114. <input type="search" id="searchbar" name="searchbar" placeholder="Search this book ..." aria-controls="searchresults-outer" aria-describedby="searchresults-header">
  115. </form>
  116. <div id="searchresults-outer" class="searchresults-outer hidden">
  117. <div id="searchresults-header" class="searchresults-header"></div>
  118. <ul id="searchresults">
  119. </ul>
  120. </div>
  121. </div>
  122. <!-- Apply ARIA attributes after the sidebar and the sidebar toggle button are added to the DOM -->
  123. <script type="text/javascript">
  124. document.getElementById('sidebar-toggle').setAttribute('aria-expanded', sidebar === 'visible');
  125. document.getElementById('sidebar').setAttribute('aria-hidden', sidebar !== 'visible');
  126. Array.from(document.querySelectorAll('#sidebar a')).forEach(function(link) {
  127. link.setAttribute('tabIndex', sidebar === 'visible' ? 0 : -1);
  128. });
  129. </script>
  130. <div id="content" class="content">
  131. <main>
  132. <!-- Page table of contents -->
  133. <div class="sidetoc">
  134. <nav class="pagetoc"></nav>
  135. </div>
  136. <h1 id="scaling-synapse-via-workers"><a class="header" href="#scaling-synapse-via-workers">Scaling synapse via workers</a></h1>
  137. <p>For small instances it is recommended to run Synapse in the default monolith mode.
  138. For larger instances where performance is a concern it can be helpful to split
  139. out functionality into multiple separate python processes. These processes are
  140. called 'workers', and are (eventually) intended to scale horizontally
  141. independently.</p>
  142. <p>Synapse's worker support is under active development and subject to change as
  143. we attempt to rapidly scale ever larger Synapse instances. However we are
  144. documenting it here to help admins needing a highly scalable Synapse instance
  145. similar to the one running <code>matrix.org</code>.</p>
  146. <p>All processes continue to share the same database instance, and as such,
  147. workers only work with PostgreSQL-based Synapse deployments. SQLite should only
  148. be used for demo purposes and any admin considering workers should already be
  149. running PostgreSQL.</p>
  150. <p>See also <a href="https://matrix.org/blog/2020/11/03/how-we-fixed-synapses-scalability">Matrix.org blog post</a>
  151. for a higher level overview.</p>
  152. <h2 id="main-processworker-communication"><a class="header" href="#main-processworker-communication">Main process/worker communication</a></h2>
  153. <p>The processes communicate with each other via a Synapse-specific protocol called
  154. 'replication' (analogous to MySQL- or Postgres-style database replication) which
  155. feeds streams of newly written data between processes so they can be kept in
  156. sync with the database state.</p>
  157. <p>When configured to do so, Synapse uses a
  158. <a href="https://redis.io/docs/manual/pubsub/">Redis pub/sub channel</a> to send the replication
  159. stream between all configured Synapse processes. Additionally, processes may
  160. make HTTP requests to each other, primarily for operations which need to wait
  161. for a reply ─ such as sending an event.</p>
  162. <p>All the workers and the main process connect to Redis, which relays replication
  163. commands between processes.</p>
  164. <p>If Redis support is enabled Synapse will use it as a shared cache, as well as a
  165. pub/sub mechanism.</p>
  166. <p>See the <a href="#architectural-diagram">Architectural diagram</a> section at the end for
  167. a visualisation of what this looks like.</p>
  168. <h2 id="setting-up-workers"><a class="header" href="#setting-up-workers">Setting up workers</a></h2>
  169. <p>A Redis server is required to manage the communication between the processes.
  170. The Redis server should be installed following the normal procedure for your
  171. distribution (e.g. <code>apt install redis-server</code> on Debian). It is safe to use an
  172. existing Redis deployment if you have one.</p>
  173. <p>Once installed, check that Redis is running and accessible from the host running
  174. Synapse, for example by executing <code>echo PING | nc -q1 localhost 6379</code> and seeing
  175. a response of <code>+PONG</code>.</p>
  176. <p>The appropriate dependencies must also be installed for Synapse. If using a
  177. virtualenv, these can be installed with:</p>
  178. <pre><code class="language-sh">pip install &quot;matrix-synapse[redis]&quot;
  179. </code></pre>
  180. <p>Note that these dependencies are included when synapse is installed with <code>pip install matrix-synapse[all]</code>. They are also included in the debian packages from
  181. <code>matrix.org</code> and in the docker images at
  182. https://hub.docker.com/r/matrixdotorg/synapse/.</p>
  183. <p>To make effective use of the workers, you will need to configure an HTTP
  184. reverse-proxy such as nginx or haproxy, which will direct incoming requests to
  185. the correct worker, or to the main synapse instance. See
  186. <a href="reverse_proxy.html">the reverse proxy documentation</a> for information on setting up a reverse
  187. proxy.</p>
  188. <p>When using workers, each worker process has its own configuration file which
  189. contains settings specific to that worker, such as the HTTP listener that it
  190. provides (if any), logging configuration, etc.</p>
  191. <p>Normally, the worker processes are configured to read from a shared
  192. configuration file as well as the worker-specific configuration files. This
  193. makes it easier to keep common configuration settings synchronised across all
  194. the processes.</p>
  195. <p>The main process is somewhat special in this respect: it does not normally
  196. need its own configuration file and can take all of its configuration from the
  197. shared configuration file.</p>
  198. <h3 id="shared-configuration"><a class="header" href="#shared-configuration">Shared configuration</a></h3>
  199. <p>Normally, only a couple of changes are needed to make an existing configuration
  200. file suitable for use with workers. First, you need to enable an
  201. <a href="usage/configuration/config_documentation.html#listeners">&quot;HTTP replication listener&quot;</a>
  202. for the main process; and secondly, you need to enable
  203. <a href="usage/configuration/config_documentation.html#redis">redis-based replication</a>.
  204. Optionally, a <a href="usage/configuration/config_documentation.html#worker_replication_secret">shared secret</a>
  205. can be used to authenticate HTTP traffic between workers. For example:</p>
  206. <pre><code class="language-yaml"># extend the existing `listeners` section. This defines the ports that the
  207. # main process will listen on.
  208. listeners:
  209. # The HTTP replication port
  210. - port: 9093
  211. bind_address: '127.0.0.1'
  212. type: http
  213. resources:
  214. - names: [replication]
  215. # Add a random shared secret to authenticate traffic.
  216. worker_replication_secret: &quot;&quot;
  217. redis:
  218. enabled: true
  219. </code></pre>
  220. <p>See the <a href="usage/configuration/config_documentation.html">configuration manual</a>
  221. for the full documentation of each option.</p>
  222. <p>Under <strong>no circumstances</strong> should the replication listener be exposed to the
  223. public internet; replication traffic is:</p>
  224. <ul>
  225. <li>always unencrypted</li>
  226. <li>unauthenticated, unless <a href="usage/configuration/config_documentation.html#worker_replication_secret"><code>worker_replication_secret</code></a>
  227. is configured</li>
  228. </ul>
  229. <h3 id="worker-configuration"><a class="header" href="#worker-configuration">Worker configuration</a></h3>
  230. <p>In the config file for each worker, you must specify:</p>
  231. <ul>
  232. <li>The type of worker (<a href="usage/configuration/config_documentation.html#worker_app"><code>worker_app</code></a>).
  233. The currently available worker applications are listed <a href="#available-worker-applications">below</a>.</li>
  234. <li>A unique name for the worker (<a href="usage/configuration/config_documentation.html#worker_name"><code>worker_name</code></a>).</li>
  235. <li>The HTTP replication endpoint that it should talk to on the main synapse process
  236. (<a href="usage/configuration/config_documentation.html#worker_replication_host"><code>worker_replication_host</code></a> and
  237. <a href="usage/configuration/config_documentation.html#worker_replication_http_port"><code>worker_replication_http_port</code></a>).</li>
  238. <li>If handling HTTP requests, a <a href="usage/configuration/config_documentation.html#worker_listeners"><code>worker_listeners</code></a> option
  239. with an <code>http</code> listener.</li>
  240. <li><strong>Synapse 1.72 and older:</strong> if handling the <code>^/_matrix/client/v3/keys/upload</code> endpoint, the HTTP URI for
  241. the main process (<code>worker_main_http_uri</code>). This config option is no longer required and is ignored when running Synapse 1.73 and newer.</li>
  242. </ul>
  243. <p>For example:</p>
  244. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  245. worker_name: generic_worker1
  246. # The replication listener on the main synapse process.
  247. worker_replication_host: 127.0.0.1
  248. worker_replication_http_port: 9093
  249. worker_listeners:
  250. - type: http
  251. port: 8083
  252. x_forwarded: true
  253. resources:
  254. - names: [client, federation]
  255. worker_log_config: /etc/matrix-synapse/generic-worker-log.yaml
  256. </code></pre>
  257. <p>...is a full configuration for a generic worker instance, which will expose a
  258. plain HTTP endpoint on port 8083 separately serving various endpoints, e.g.
  259. <code>/sync</code>, which are listed below.</p>
  260. <p>Obviously you should configure your reverse-proxy to route the relevant
  261. endpoints to the worker (<code>localhost:8083</code> in the above example).</p>
  262. <h3 id="running-synapse-with-workers"><a class="header" href="#running-synapse-with-workers">Running Synapse with workers</a></h3>
  263. <p>Finally, you need to start your worker processes. This can be done with either
  264. <code>synctl</code> or your distribution's preferred service manager such as <code>systemd</code>. We
  265. recommend the use of <code>systemd</code> where available: for information on setting up
  266. <code>systemd</code> to start synapse workers, see
  267. <a href="systemd-with-workers/">Systemd with Workers</a>. To use <code>synctl</code>, see
  268. <a href="synctl_workers.html">Using synctl with Workers</a>.</p>
  269. <h2 id="start-synapse-with-poetry"><a class="header" href="#start-synapse-with-poetry">Start Synapse with Poetry</a></h2>
  270. <p>The following applies to Synapse installations that have been installed from source using <code>poetry</code>.</p>
  271. <p>You can start the main Synapse process with Poetry by running the following command:</p>
  272. <pre><code class="language-console">poetry run synapse_homeserver -c [your homeserver.yaml]
  273. </code></pre>
  274. <p>For worker setups, you can run the following command</p>
  275. <pre><code class="language-console">poetry run synapse_worker -c [your worker.yaml]
  276. </code></pre>
  277. <h2 id="available-worker-applications"><a class="header" href="#available-worker-applications">Available worker applications</a></h2>
  278. <h3 id="synapseappgeneric_worker"><a class="header" href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a></h3>
  279. <p>This worker can handle API requests matching the following regular expressions.
  280. These endpoints can be routed to any worker. If a worker is set up to handle a
  281. stream then, for maximum efficiency, additional endpoints should be routed to that
  282. worker: refer to the <a href="#stream-writers">stream writers</a> section below for further
  283. information.</p>
  284. <pre><code># Sync requests
  285. ^/_matrix/client/(r0|v3)/sync$
  286. ^/_matrix/client/(api/v1|r0|v3)/events$
  287. ^/_matrix/client/(api/v1|r0|v3)/initialSync$
  288. ^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$
  289. # Federation requests
  290. ^/_matrix/federation/v1/event/
  291. ^/_matrix/federation/v1/state/
  292. ^/_matrix/federation/v1/state_ids/
  293. ^/_matrix/federation/v1/backfill/
  294. ^/_matrix/federation/v1/get_missing_events/
  295. ^/_matrix/federation/v1/publicRooms
  296. ^/_matrix/federation/v1/query/
  297. ^/_matrix/federation/v1/make_join/
  298. ^/_matrix/federation/v1/make_leave/
  299. ^/_matrix/federation/(v1|v2)/send_join/
  300. ^/_matrix/federation/(v1|v2)/send_leave/
  301. ^/_matrix/federation/(v1|v2)/invite/
  302. ^/_matrix/federation/v1/event_auth/
  303. ^/_matrix/federation/v1/timestamp_to_event/
  304. ^/_matrix/federation/v1/exchange_third_party_invite/
  305. ^/_matrix/federation/v1/user/devices/
  306. ^/_matrix/key/v2/query
  307. ^/_matrix/federation/v1/hierarchy/
  308. # Inbound federation transaction request
  309. ^/_matrix/federation/v1/send/
  310. # Client API requests
  311. ^/_matrix/client/(api/v1|r0|v3|unstable)/createRoom$
  312. ^/_matrix/client/(api/v1|r0|v3|unstable)/publicRooms$
  313. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/joined_members$
  314. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/context/.*$
  315. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/members$
  316. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state$
  317. ^/_matrix/client/v1/rooms/.*/hierarchy$
  318. ^/_matrix/client/(v1|unstable)/rooms/.*/relations/
  319. ^/_matrix/client/v1/rooms/.*/threads$
  320. ^/_matrix/client/unstable/org.matrix.msc2716/rooms/.*/batch_send$
  321. ^/_matrix/client/unstable/im.nheko.summary/rooms/.*/summary$
  322. ^/_matrix/client/(r0|v3|unstable)/account/3pid$
  323. ^/_matrix/client/(r0|v3|unstable)/account/whoami$
  324. ^/_matrix/client/(r0|v3|unstable)/devices$
  325. ^/_matrix/client/versions$
  326. ^/_matrix/client/(api/v1|r0|v3|unstable)/voip/turnServer$
  327. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/event/
  328. ^/_matrix/client/(api/v1|r0|v3|unstable)/joined_rooms$
  329. ^/_matrix/client/v1/rooms/.*/timestamp_to_event$
  330. ^/_matrix/client/(api/v1|r0|v3|unstable/.*)/rooms/.*/aliases
  331. ^/_matrix/client/(api/v1|r0|v3|unstable)/search$
  332. ^/_matrix/client/(r0|v3|unstable)/user/.*/filter(/|$)
  333. # Encryption requests
  334. ^/_matrix/client/(r0|v3|unstable)/keys/query$
  335. ^/_matrix/client/(r0|v3|unstable)/keys/changes$
  336. ^/_matrix/client/(r0|v3|unstable)/keys/claim$
  337. ^/_matrix/client/(r0|v3|unstable)/room_keys/
  338. ^/_matrix/client/(r0|v3|unstable)/keys/upload/
  339. # Registration/login requests
  340. ^/_matrix/client/(api/v1|r0|v3|unstable)/login$
  341. ^/_matrix/client/(r0|v3|unstable)/register$
  342. ^/_matrix/client/(r0|v3|unstable)/register/available$
  343. ^/_matrix/client/v1/register/m.login.registration_token/validity$
  344. # Event sending requests
  345. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/redact
  346. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/send
  347. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/state/
  348. ^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/(join|invite|leave|ban|unban|kick)$
  349. ^/_matrix/client/(api/v1|r0|v3|unstable)/join/
  350. ^/_matrix/client/(api/v1|r0|v3|unstable)/knock/
  351. ^/_matrix/client/(api/v1|r0|v3|unstable)/profile/
  352. # Account data requests
  353. ^/_matrix/client/(r0|v3|unstable)/.*/tags
  354. ^/_matrix/client/(r0|v3|unstable)/.*/account_data
  355. # Receipts requests
  356. ^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt
  357. ^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers
  358. # Presence requests
  359. ^/_matrix/client/(api/v1|r0|v3|unstable)/presence/
  360. # User directory search requests
  361. ^/_matrix/client/(r0|v3|unstable)/user_directory/search$
  362. </code></pre>
  363. <p>Additionally, the following REST endpoints can be handled for GET requests:</p>
  364. <pre><code>^/_matrix/client/(api/v1|r0|v3|unstable)/pushrules/
  365. </code></pre>
  366. <p>Pagination requests can also be handled, but all requests for a given
  367. room must be routed to the same instance. Additionally, care must be taken to
  368. ensure that the purge history admin API is not used while pagination requests
  369. for the room are in flight:</p>
  370. <pre><code>^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/messages$
  371. </code></pre>
  372. <p>Additionally, the following endpoints should be included if Synapse is configured
  373. to use SSO (you only need to include the ones for whichever SSO provider you're
  374. using):</p>
  375. <pre><code># for all SSO providers
  376. ^/_matrix/client/(api/v1|r0|v3|unstable)/login/sso/redirect
  377. ^/_synapse/client/pick_idp$
  378. ^/_synapse/client/pick_username
  379. ^/_synapse/client/new_user_consent$
  380. ^/_synapse/client/sso_register$
  381. # OpenID Connect requests.
  382. ^/_synapse/client/oidc/callback$
  383. # SAML requests.
  384. ^/_synapse/client/saml2/authn_response$
  385. # CAS requests.
  386. ^/_matrix/client/(api/v1|r0|v3|unstable)/login/cas/ticket$
  387. </code></pre>
  388. <p>Ensure that all SSO logins go to a single process.
  389. For multiple workers not handling the SSO endpoints properly, see
  390. <a href="https://github.com/matrix-org/synapse/issues/7530">#7530</a> and
  391. <a href="https://github.com/matrix-org/synapse/issues/9427">#9427</a>.</p>
  392. <p>Note that a <a href="usage/configuration/config_documentation.html#listeners">HTTP listener</a>
  393. with <code>client</code> and <code>federation</code> <code>resources</code> must be configured in the
  394. <a href="usage/configuration/config_documentation.html#worker_listeners"><code>worker_listeners</code></a>
  395. option in the worker config.</p>
  396. <h4 id="load-balancing"><a class="header" href="#load-balancing">Load balancing</a></h4>
  397. <p>It is possible to run multiple instances of this worker app, with incoming requests
  398. being load-balanced between them by the reverse-proxy. However, different endpoints
  399. have different characteristics and so admins
  400. may wish to run multiple groups of workers handling different endpoints so that
  401. load balancing can be done in different ways.</p>
  402. <p>For <code>/sync</code> and <code>/initialSync</code> requests it will be more efficient if all
  403. requests from a particular user are routed to a single instance. This can
  404. be done e.g. in nginx via IP <code>hash $http_x_forwarded_for;</code> or via
  405. <code>hash $http_authorization consistent;</code> which contains the users access token.</p>
  406. <p>Admins may additionally wish to separate out <code>/sync</code>
  407. requests that have a <code>since</code> query parameter from those that don't (and
  408. <code>/initialSync</code>), as requests that don't are known as &quot;initial sync&quot; that happens
  409. when a user logs in on a new device and can be <em>very</em> resource intensive, so
  410. isolating these requests will stop them from interfering with other users ongoing
  411. syncs.</p>
  412. <p>Federation and client requests can be balanced via simple round robin.</p>
  413. <p>The inbound federation transaction request <code>^/_matrix/federation/v1/send/</code>
  414. should be balanced by source IP so that transactions from the same remote server
  415. go to the same process.</p>
  416. <p>Registration/login requests can be handled separately purely to help ensure that
  417. unexpected load doesn't affect new logins and sign ups.</p>
  418. <p>Finally, event sending requests can be balanced by the room ID in the URI (or
  419. the full URI, or even just round robin), the room ID is the path component after
  420. <code>/rooms/</code>. If there is a large bridge connected that is sending or may send lots
  421. of events, then a dedicated set of workers can be provisioned to limit the
  422. effects of bursts of events from that bridge on events sent by normal users.</p>
  423. <h4 id="stream-writers"><a class="header" href="#stream-writers">Stream writers</a></h4>
  424. <p>Additionally, the writing of specific streams (such as events) can be moved off
  425. of the main process to a particular worker.</p>
  426. <p>To enable this, the worker must have a
  427. <a href="usage/configuration/config_documentation.html#listeners">HTTP <code>replication</code> listener</a> configured,
  428. have a <a href="usage/configuration/config_documentation.html#worker_name"><code>worker_name</code></a>
  429. and be listed in the <a href="usage/configuration/config_documentation.html#instance_map"><code>instance_map</code></a>
  430. config. The same worker can handle multiple streams, but unless otherwise documented,
  431. each stream can only have a single writer.</p>
  432. <p>For example, to move event persistence off to a dedicated worker, the shared
  433. configuration would include:</p>
  434. <pre><code class="language-yaml">instance_map:
  435. event_persister1:
  436. host: localhost
  437. port: 8034
  438. stream_writers:
  439. events: event_persister1
  440. </code></pre>
  441. <p>An example for a stream writer instance:</p>
  442. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  443. worker_name: event_persister1
  444. # The replication listener on the main synapse process.
  445. worker_replication_host: 127.0.0.1
  446. worker_replication_http_port: 9093
  447. worker_listeners:
  448. - type: http
  449. port: 8034
  450. resources:
  451. - names: [replication]
  452. # Enable listener if this stream writer handles endpoints for the `typing` or
  453. # `to_device` streams. Uses a different port to the `replication` listener to
  454. # avoid exposing the `replication` listener publicly.
  455. #
  456. #- type: http
  457. # port: 8035
  458. # x_forwarded: true
  459. # resources:
  460. # - names: [client]
  461. worker_log_config: /etc/matrix-synapse/event-persister-log.yaml
  462. </code></pre>
  463. <p>Some of the streams have associated endpoints which, for maximum efficiency, should
  464. be routed to the workers handling that stream. See below for the currently supported
  465. streams and the endpoints associated with them:</p>
  466. <h5 id="the-events-stream"><a class="header" href="#the-events-stream">The <code>events</code> stream</a></h5>
  467. <p>The <code>events</code> stream experimentally supports having multiple writer workers, where load
  468. is sharded between them by room ID. Each writer is called an <em>event persister</em>. They are
  469. responsible for</p>
  470. <ul>
  471. <li>receiving new events,</li>
  472. <li>linking them to those already in the room <a href="development/room-dag-concepts.html">DAG</a>,</li>
  473. <li>persisting them to the DB, and finally</li>
  474. <li>updating the events stream.</li>
  475. </ul>
  476. <p>Because load is sharded in this way, you <em>must</em> restart all worker instances when
  477. adding or removing event persisters.</p>
  478. <p>An <code>event_persister</code> should not be mistaken for an <code>event_creator</code>.
  479. An <code>event_creator</code> listens for requests from clients to create new events and does
  480. so. It will then pass those events over HTTP replication to any configured event
  481. persisters (or the main process if none are configured).</p>
  482. <p>Note that <code>event_creator</code>s and <code>event_persister</code>s are implemented using the same
  483. <a href="#synapseappgeneric_worker"><code>synapse.app.generic_worker</code></a>.</p>
  484. <p>An example <a href="usage/configuration/config_documentation.html#stream_writers"><code>stream_writers</code></a>
  485. configuration with multiple writers:</p>
  486. <pre><code class="language-yaml">stream_writers:
  487. events:
  488. - event_persister1
  489. - event_persister2
  490. </code></pre>
  491. <h5 id="the-typing-stream"><a class="header" href="#the-typing-stream">The <code>typing</code> stream</a></h5>
  492. <p>The following endpoints should be routed directly to the worker configured as
  493. the stream writer for the <code>typing</code> stream:</p>
  494. <pre><code>^/_matrix/client/(api/v1|r0|v3|unstable)/rooms/.*/typing
  495. </code></pre>
  496. <h5 id="the-to_device-stream"><a class="header" href="#the-to_device-stream">The <code>to_device</code> stream</a></h5>
  497. <p>The following endpoints should be routed directly to the worker configured as
  498. the stream writer for the <code>to_device</code> stream:</p>
  499. <pre><code>^/_matrix/client/(r0|v3|unstable)/sendToDevice/
  500. </code></pre>
  501. <h5 id="the-account_data-stream"><a class="header" href="#the-account_data-stream">The <code>account_data</code> stream</a></h5>
  502. <p>The following endpoints should be routed directly to the worker configured as
  503. the stream writer for the <code>account_data</code> stream:</p>
  504. <pre><code>^/_matrix/client/(r0|v3|unstable)/.*/tags
  505. ^/_matrix/client/(r0|v3|unstable)/.*/account_data
  506. </code></pre>
  507. <h5 id="the-receipts-stream"><a class="header" href="#the-receipts-stream">The <code>receipts</code> stream</a></h5>
  508. <p>The following endpoints should be routed directly to the worker configured as
  509. the stream writer for the <code>receipts</code> stream:</p>
  510. <pre><code>^/_matrix/client/(r0|v3|unstable)/rooms/.*/receipt
  511. ^/_matrix/client/(r0|v3|unstable)/rooms/.*/read_markers
  512. </code></pre>
  513. <h5 id="the-presence-stream"><a class="header" href="#the-presence-stream">The <code>presence</code> stream</a></h5>
  514. <p>The following endpoints should be routed directly to the worker configured as
  515. the stream writer for the <code>presence</code> stream:</p>
  516. <pre><code>^/_matrix/client/(api/v1|r0|v3|unstable)/presence/
  517. </code></pre>
  518. <h4 id="background-tasks"><a class="header" href="#background-tasks">Background tasks</a></h4>
  519. <p>There is also support for moving background tasks to a separate
  520. worker. Background tasks are run periodically or started via replication. Exactly
  521. which tasks are configured to run depends on your Synapse configuration (e.g. if
  522. stats is enabled). This worker doesn't handle any REST endpoints itself.</p>
  523. <p>To enable this, the worker must have a unique
  524. <a href="usage/configuration/config_documentation.html#worker_name"><code>worker_name</code></a>
  525. and can be configured to run background tasks. For example, to move background tasks
  526. to a dedicated worker, the shared configuration would include:</p>
  527. <pre><code class="language-yaml">run_background_tasks_on: background_worker
  528. </code></pre>
  529. <p>You might also wish to investigate the
  530. <a href="#updating-the-user-directory"><code>update_user_directory_from_worker</code></a> and
  531. <a href="#synapseappmedia_repository"><code>media_instance_running_background_jobs</code></a> settings.</p>
  532. <p>An example for a dedicated background worker instance:</p>
  533. <pre><code class="language-yaml">worker_app: synapse.app.generic_worker
  534. worker_name: background_worker
  535. # The replication listener on the main synapse process.
  536. worker_replication_host: 127.0.0.1
  537. worker_replication_http_port: 9093
  538. worker_log_config: /etc/matrix-synapse/background-worker-log.yaml
  539. </code></pre>
  540. <h4 id="updating-the-user-directory"><a class="header" href="#updating-the-user-directory">Updating the User Directory</a></h4>
  541. <p>You can designate one generic worker to update the user directory.</p>
  542. <p>Specify its name in the <a href="usage/configuration/config_documentation.html#update_user_directory_from_worker">shared configuration</a>
  543. as follows:</p>
  544. <pre><code class="language-yaml">update_user_directory_from_worker: worker_name
  545. </code></pre>
  546. <p>This work cannot be load-balanced; please ensure the main process is restarted
  547. after setting this option in the shared configuration!</p>
  548. <p>User directory updates allow REST endpoints matching the following regular
  549. expressions to work:</p>
  550. <pre><code>^/_matrix/client/(r0|v3|unstable)/user_directory/search$
  551. </code></pre>
  552. <p>The above endpoints can be routed to any worker, though you may choose to route
  553. it to the chosen user directory worker.</p>
  554. <p>This style of configuration supersedes the legacy <code>synapse.app.user_dir</code>
  555. worker application type.</p>
  556. <h4 id="notifying-application-services"><a class="header" href="#notifying-application-services">Notifying Application Services</a></h4>
  557. <p>You can designate one generic worker to send output traffic to Application Services.
  558. Doesn't handle any REST endpoints itself, but you should specify its name in the
  559. <a href="usage/configuration/config_documentation.html#notify_appservices_from_worker">shared configuration</a>
  560. as follows:</p>
  561. <pre><code class="language-yaml">notify_appservices_from_worker: worker_name
  562. </code></pre>
  563. <p>This work cannot be load-balanced; please ensure the main process is restarted
  564. after setting this option in the shared configuration!</p>
  565. <p>This style of configuration supersedes the legacy <code>synapse.app.appservice</code>
  566. worker application type.</p>
  567. <h4 id="push-notifications"><a class="header" href="#push-notifications">Push Notifications</a></h4>
  568. <p>You can designate generic worker to sending push notifications to
  569. a <a href="https://spec.matrix.org/v1.5/push-gateway-api/">push gateway</a> such as
  570. <a href="https://github.com/matrix-org/sygnal">sygnal</a> and email.</p>
  571. <p>This will stop the main process sending push notifications.</p>
  572. <p>The workers responsible for sending push notifications can be defined using the
  573. <a href="usage/configuration/config_documentation.html#pusher_instances"><code>pusher_instances</code></a>
  574. option. For example:</p>
  575. <pre><code class="language-yaml">pusher_instances:
  576. - pusher_worker1
  577. - pusher_worker2
  578. </code></pre>
  579. <p>Multiple workers can be added to this map, in which case the work is balanced
  580. across them. Ensure the main process and all pusher workers are restarted after changing
  581. this option.</p>
  582. <p>These workers don't need to accept incoming HTTP requests to send push notifications,
  583. so no additional reverse proxy configuration is required for pusher workers.</p>
  584. <p>This style of configuration supersedes the legacy <code>synapse.app.pusher</code>
  585. worker application type.</p>
  586. <h3 id="synapseapppusher"><a class="header" href="#synapseapppusher"><code>synapse.app.pusher</code></a></h3>
  587. <p>It is likely this option will be deprecated in the future and is not recommended for new
  588. installations. Instead, <a href="#push-notifications">use <code>synapse.app.generic_worker</code> with the <code>pusher_instances</code></a>.</p>
  589. <p>Handles sending push notifications to sygnal and email. Doesn't handle any
  590. REST endpoints itself, but you should set
  591. <a href="usage/configuration/config_documentation.html#start_pushers"><code>start_pushers: false</code></a> in the
  592. shared configuration file to stop the main synapse sending push notifications.</p>
  593. <p>To run multiple instances at once the
  594. <a href="usage/configuration/config_documentation.html#pusher_instances"><code>pusher_instances</code></a>
  595. option should list all pusher instances by their
  596. <a href="usage/configuration/config_documentation.html#worker_name"><code>worker_name</code></a>, e.g.:</p>
  597. <pre><code class="language-yaml">start_pushers: false
  598. pusher_instances:
  599. - pusher_worker1
  600. - pusher_worker2
  601. </code></pre>
  602. <p>An example for a pusher instance:</p>
  603. <pre><code class="language-yaml">worker_app: synapse.app.pusher
  604. worker_name: pusher_worker1
  605. # The replication listener on the main synapse process.
  606. worker_replication_host: 127.0.0.1
  607. worker_replication_http_port: 9093
  608. worker_log_config: /etc/matrix-synapse/pusher-worker-log.yaml
  609. </code></pre>
  610. <h3 id="synapseappappservice"><a class="header" href="#synapseappappservice"><code>synapse.app.appservice</code></a></h3>
  611. <p><strong>Deprecated as of Synapse v1.59.</strong> <a href="#notifying-application-services">Use <code>synapse.app.generic_worker</code> with the
  612. <code>notify_appservices_from_worker</code> option instead.</a></p>
  613. <p>Handles sending output traffic to Application Services. Doesn't handle any
  614. REST endpoints itself, but you should set <code>notify_appservices: False</code> in the
  615. shared configuration file to stop the main synapse sending appservice notifications.</p>
  616. <p>Note this worker cannot be load-balanced: only one instance should be active.</p>
  617. <h3 id="synapseappfederation_sender"><a class="header" href="#synapseappfederation_sender"><code>synapse.app.federation_sender</code></a></h3>
  618. <p>It is likely this option will be deprecated in the future and not recommended for
  619. new installations. Instead, <a href="usage/configuration/config_documentation.html#federation_sender_instances">use <code>synapse.app.generic_worker</code> with the <code>federation_sender_instances</code></a>.</p>
  620. <p>Handles sending federation traffic to other servers. Doesn't handle any
  621. REST endpoints itself, but you should set
  622. <a href="usage/configuration/config_documentation.html#send_federation"><code>send_federation: false</code></a>
  623. in the shared configuration file to stop the main synapse sending this traffic.</p>
  624. <p>If running multiple federation senders then you must list each
  625. instance in the
  626. <a href="usage/configuration/config_documentation.html#federation_sender_instances"><code>federation_sender_instances</code></a>
  627. option by their
  628. <a href="usage/configuration/config_documentation.html#worker_name"><code>worker_name</code></a>.
  629. All instances must be stopped and started when adding or removing instances.
  630. For example:</p>
  631. <pre><code class="language-yaml">send_federation: false
  632. federation_sender_instances:
  633. - federation_sender1
  634. - federation_sender2
  635. </code></pre>
  636. <p>An example for a federation sender instance:</p>
  637. <pre><code class="language-yaml">worker_app: synapse.app.federation_sender
  638. worker_name: federation_sender1
  639. # The replication listener on the main synapse process.
  640. worker_replication_host: 127.0.0.1
  641. worker_replication_http_port: 9093
  642. worker_log_config: /etc/matrix-synapse/federation-sender-log.yaml
  643. </code></pre>
  644. <h3 id="synapseappmedia_repository"><a class="header" href="#synapseappmedia_repository"><code>synapse.app.media_repository</code></a></h3>
  645. <p>Handles the media repository. It can handle all endpoints starting with:</p>
  646. <pre><code>/_matrix/media/
  647. </code></pre>
  648. <p>... and the following regular expressions matching media-specific administration APIs:</p>
  649. <pre><code>^/_synapse/admin/v1/purge_media_cache$
  650. ^/_synapse/admin/v1/room/.*/media.*$
  651. ^/_synapse/admin/v1/user/.*/media.*$
  652. ^/_synapse/admin/v1/media/.*$
  653. ^/_synapse/admin/v1/quarantine_media/.*$
  654. ^/_synapse/admin/v1/users/.*/media$
  655. </code></pre>
  656. <p>You should also set
  657. <a href="usage/configuration/config_documentation.html#enable_media_repo"><code>enable_media_repo: False</code></a>
  658. in the shared configuration
  659. file to stop the main synapse running background jobs related to managing the
  660. media repository. Note that doing so will prevent the main process from being
  661. able to handle the above endpoints.</p>
  662. <p>In the <code>media_repository</code> worker configuration file, configure the
  663. <a href="usage/configuration/config_documentation.html#listeners">HTTP listener</a> to
  664. expose the <code>media</code> resource. For example:</p>
  665. <pre><code class="language-yaml">worker_app: synapse.app.media_repository
  666. worker_name: media_worker
  667. # The replication listener on the main synapse process.
  668. worker_replication_host: 127.0.0.1
  669. worker_replication_http_port: 9093
  670. worker_listeners:
  671. - type: http
  672. port: 8085
  673. x_forwarded: true
  674. resources:
  675. - names: [media]
  676. worker_log_config: /etc/matrix-synapse/media-worker-log.yaml
  677. </code></pre>
  678. <p>Note that if running multiple media repositories they must be on the same server
  679. and you must specify a single instance to run the background tasks in the
  680. <a href="usage/configuration/config_documentation.html#media_instance_running_background_jobs">shared configuration</a>,
  681. e.g.:</p>
  682. <pre><code class="language-yaml">media_instance_running_background_jobs: &quot;media-repository-1&quot;
  683. </code></pre>
  684. <p>Note that if a reverse proxy is used , then <code>/_matrix/media/</code> must be routed for both inbound client and federation requests (if they are handled separately).</p>
  685. <h3 id="synapseappuser_dir"><a class="header" href="#synapseappuser_dir"><code>synapse.app.user_dir</code></a></h3>
  686. <p><strong>Deprecated as of Synapse v1.59.</strong> <a href="#updating-the-user-directory">Use <code>synapse.app.generic_worker</code> with the
  687. <code>update_user_directory_from_worker</code> option instead.</a></p>
  688. <p>Handles searches in the user directory. It can handle REST endpoints matching
  689. the following regular expressions:</p>
  690. <pre><code>^/_matrix/client/(r0|v3|unstable)/user_directory/search$
  691. </code></pre>
  692. <p>When using this worker you must also set <code>update_user_directory: false</code> in the
  693. shared configuration file to stop the main synapse running background
  694. jobs related to updating the user directory.</p>
  695. <p>Above endpoint is not <em>required</em> to be routed to this worker. By default,
  696. <code>update_user_directory</code> is set to <code>true</code>, which means the main process
  697. will handle updates. All workers configured with <code>client</code> can handle the above
  698. endpoint as long as either this worker or the main process are configured to
  699. handle it, and are online.</p>
  700. <p>If <code>update_user_directory</code> is set to <code>false</code>, and this worker is not running,
  701. the above endpoint may give outdated results.</p>
  702. <h3 id="historical-apps"><a class="header" href="#historical-apps">Historical apps</a></h3>
  703. <p>The following used to be separate worker application types, but are now
  704. equivalent to <code>synapse.app.generic_worker</code>:</p>
  705. <ul>
  706. <li><code>synapse.app.client_reader</code></li>
  707. <li><code>synapse.app.event_creator</code></li>
  708. <li><code>synapse.app.federation_reader</code></li>
  709. <li><code>synapse.app.federation_sender</code></li>
  710. <li><code>synapse.app.frontend_proxy</code></li>
  711. <li><code>synapse.app.pusher</code></li>
  712. <li><code>synapse.app.synchrotron</code></li>
  713. </ul>
  714. <h2 id="migration-from-old-config"><a class="header" href="#migration-from-old-config">Migration from old config</a></h2>
  715. <p>A main change that has occurred is the merging of worker apps into
  716. <code>synapse.app.generic_worker</code>. This change is backwards compatible and so no
  717. changes to the config are required.</p>
  718. <p>To migrate apps to use <code>synapse.app.generic_worker</code> simply update the
  719. <code>worker_app</code> option in the worker configs, and where worker are started (e.g.
  720. in systemd service files, but not required for synctl).</p>
  721. <h2 id="architectural-diagram"><a class="header" href="#architectural-diagram">Architectural diagram</a></h2>
  722. <p>The following shows an example setup using Redis and a reverse proxy:</p>
  723. <pre><code> Clients &amp; Federation
  724. |
  725. v
  726. +-----------+
  727. | |
  728. | Reverse |
  729. | Proxy |
  730. | |
  731. +-----------+
  732. | | |
  733. | | | HTTP requests
  734. +-------------------+ | +-----------+
  735. | +---+ |
  736. | | |
  737. v v v
  738. +--------------+ +--------------+ +--------------+ +--------------+
  739. | Main | | Generic | | Generic | | Event |
  740. | Process | | Worker 1 | | Worker 2 | | Persister |
  741. +--------------+ +--------------+ +--------------+ +--------------+
  742. ^ ^ | ^ | | ^ | | ^ ^
  743. | | | | | | | | | | |
  744. | | | | | HTTP | | | | | |
  745. | +----------+&lt;--|---|---------+&lt;--|---|---------+ | |
  746. | | +-------------|--&gt;+-------------+ |
  747. | | | |
  748. | | | |
  749. v v v v
  750. ======================================================================
  751. Redis pub/sub channel
  752. </code></pre>
  753. </main>
  754. <nav class="nav-wrapper" aria-label="Page navigation">
  755. <!-- Mobile navigation buttons -->
  756. <a rel="prev" href="modules/porting_legacy_module.html" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  757. <i class="fa fa-angle-left"></i>
  758. </a>
  759. <a rel="next" href="synctl_workers.html" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  760. <i class="fa fa-angle-right"></i>
  761. </a>
  762. <div style="clear: both"></div>
  763. </nav>
  764. </div>
  765. </div>
  766. <nav class="nav-wide-wrapper" aria-label="Page navigation">
  767. <a rel="prev" href="modules/porting_legacy_module.html" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
  768. <i class="fa fa-angle-left"></i>
  769. </a>
  770. <a rel="next" href="synctl_workers.html" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
  771. <i class="fa fa-angle-right"></i>
  772. </a>
  773. </nav>
  774. </div>
  775. <script type="text/javascript">
  776. window.playground_copyable = true;
  777. </script>
  778. <script src="elasticlunr.min.js" type="text/javascript" charset="utf-8"></script>
  779. <script src="mark.min.js" type="text/javascript" charset="utf-8"></script>
  780. <script src="searcher.js" type="text/javascript" charset="utf-8"></script>
  781. <script src="clipboard.min.js" type="text/javascript" charset="utf-8"></script>
  782. <script src="highlight.js" type="text/javascript" charset="utf-8"></script>
  783. <script src="book.js" type="text/javascript" charset="utf-8"></script>
  784. <!-- Custom JS scripts -->
  785. <script type="text/javascript" src="docs/website_files/table-of-contents.js"></script>
  786. </body>
  787. </html>