element-hq / element-hq/synapse

Consider using asyncioreactor

Open
#8,642 0 comments 0 reactions 0 assignees View on GitHub
A-Performance O-Occasional S-Minor T-Task
Dominant language
Python
Stars
4.6k
Forks
600
Avg merge
5d 22h
Merged PRs (30d)
51

Description

This issue has been migrated from [#8642](https://github.com/matrix-org/synapse/issues/8642).

---

### Idea

Use `twisted.internet.asyncioreactor` for synapse's twisted reactor.

### Description

This is part of my idea that synapse should consider moving forward, beyond, or at least *next* to twisted, to also use `asyncio`'s economy of libraries and functions. With the `asyncioreactor`, it's possible to mix `twisted` and `asyncio` functionality with eachother.

It's also possible to use [`uvloop`](https://github.com/MagicStack/uvloop) in addition to this, allowing a big IO performance boost.

Some links:

`asyncioreactor`: https://twistedmatrix.com/documents/current/api/twisted.internet.asyncioreactor.html

`asyncio`/`twisted` intermixing: https://gist.github.com/ldjebran/4febf298232a6fd86871df25d4dc00dd

`Deferred.asFuture()`: https://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html#asFuture

Twisted and Asyncio (blog post): https://meejah.ca/blog/python3-twisted-and-asyncio

### Considerations

I have two concerns with doing this:

1. Will the existing twisted-based code be stable on a new reactor based out of `asyncio`?

2. Will the reactor impact performance (negatively)?

For 1, I want to run a server along my existing one, only joining some channels, and watch out for any crashes and the like, and/or perform test benches with `asyncioreactor` selected.

For 2, I'd want to know what the best way is for me to collect such statistics and/or how to compare them with a normal server.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing Synapse's current Twisted reactor setup and the documented asyncioreactor integration. Investigate whether existing Twisted-based code remains stable with asyncio, then define a reproducible comparison using a normal reactor and asyncioreactor, including the proposed uvloop option. Done requires agreed stability and performance evidence plus a scoped implementation plan.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.