Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/20100.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve server concurrency by opening local media thumbnails asynchronously. Contributed by @guillemo12.
4 changes: 3 additions & 1 deletion synapse/media/thumbnailer.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Err, that benchmark script calls /_matrix/client/v1/media/thumbnail/localhost/{media_id}, which is handled by ThumbnailResource, which sets for_federation=False:

if self._is_mine_server_name(server_name):
if self.dynamic_thumbnails:
await self.thumbnailer.select_or_generate_local_thumbnail(
request,
media_id,
width,
height,
method,
m_type,
max_timeout_ms,
False,
animated=animated,
)
else:
await self.thumbnailer.respond_local_thumbnail(
request,
media_id,
width,
height,
method,
m_type,
max_timeout_ms,
False,
)

which bypasses the code changed in this PR. So I wouldn't use it as a reliable marker that this change improves performance.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from synapse.config.repository import THUMBNAIL_SUPPORTED_MEDIA_FORMAT_MAP
from synapse.http.server import respond_with_json
from synapse.http.site import SynapseRequest
from synapse.logging.context import defer_to_thread
from synapse.logging.opentracing import trace
from synapse.media._base import (
FileInfo,
Expand Down Expand Up @@ -533,10 +534,11 @@ async def select_or_generate_local_thumbnail(
assert file_info.thumbnail is not None

if for_federation:
f = await defer_to_thread(self.hs.get_reactor(), open, file_path, "rb")
await respond_with_multipart_responder(
self.hs.get_clock(),
request,
FileResponder(self.hs, open(file_path, "rb")),
FileResponder(self.hs, f),
Comment thread
guillemo12 marked this conversation as resolved.
file_info.thumbnail.type,
file_info.thumbnail.length,
None,
Expand Down
Loading