Compare commits

...

12 Commits

Author SHA1 Message Date
Erik Johnston
7b6afa5a9b Merge branch 'erikj/perf_room_members_fix' of github.com:matrix-org/synapse into erikj/profile_rununtilconcurrent 2015-06-01 15:05:52 +01:00
Erik Johnston
8c7ca6d2c0 Remove rogue @inlineCallbacks 2015-06-01 15:05:41 +01:00
Erik Johnston
d92b3884cc Merge branch 'erikj/perf_room_members_fix' of github.com:matrix-org/synapse into erikj/profile_rununtilconcurrent 2015-06-01 15:03:47 +01:00
Erik Johnston
689b4de314 Also cache user_id -> UserID conversion 2015-06-01 14:55:02 +01:00
Erik Johnston
7f20f01370 Use pyinstrument 2015-05-29 14:31:39 +01:00
Erik Johnston
38a84884da merge branch 'erikj/ultrajson' of github.com:matrix-org/synapse into erikj/profile_rununtilconcurrent 2015-05-29 13:12:06 +01:00
Erik Johnston
c7fcb53b92 Use cProfile. Hook into doIteration. Track utime. 2015-05-29 10:37:41 +01:00
Erik Johnston
06c4124f8e Merge branch 'develop' of github.com:matrix-org/synapse into erikj/profile_rununtilconcurrent 2015-05-29 09:57:43 +01:00
Erik Johnston
b037fe7485 Use pyinstrument 2015-05-27 15:35:57 +01:00
Erik Johnston
52b81be96e Include duration in output name 2015-05-27 15:32:12 +01:00
Erik Johnston
2b0eb839db Use pyinstrument 2015-05-27 15:31:00 +01:00
Erik Johnston
9f4e9fcb63 Profile and output long iterations of runUntilConcurrent 2015-05-27 14:40:21 +01:00
4 changed files with 40 additions and 16 deletions

View File

@@ -520,27 +520,46 @@ class SynapseSite(Site):
def run(hs):
PROFILE_SYNAPSE = False
PROFILE_SYNAPSE = True
if PROFILE_SYNAPSE:
def profile(func):
from cProfile import Profile
from pyinstrument import Profiler
from threading import current_thread
import time
import resource
def profiled(*args, **kargs):
profile = Profile()
profile.enable()
profile = Profiler()
rusage = resource.getrusage(resource.RUSAGE_SELF)
start_utime = rusage.ru_utime * 1000
start = int(time.time()*1000)
profile.start()
func(*args, **kargs)
profile.disable()
ident = current_thread().ident
profile.dump_stats("/tmp/%s.%s.%i.pstat" % (
hs.hostname, func.__name__, ident
))
profile.stop()
end = int(time.time()*1000)
rusage = resource.getrusage(resource.RUSAGE_SELF)
end_utime = rusage.ru_utime * 1000
if end_utime - start_utime > 50:
ident = current_thread().ident
name = "/tmp/%s.%s.%i.%d-%d.%d-%d" % (
hs.hostname, func.__name__, ident, start, end,
end-start, end_utime - start_utime,
)
# profile.dump_stats(name + ".html")
html = profile.output_html()
with open(name + ".html", "w") as f:
f.write(html)
return profiled
from twisted.python.threadpool import ThreadPool
ThreadPool._worker = profile(ThreadPool._worker)
reactor.run = profile(reactor.run)
# from twisted.python.threadpool import ThreadPool
# ThreadPool._worker = profile(ThreadPool._worker)
reactor.runUntilCurrent = profile(reactor.runUntilCurrent)
reactor.doIteration = profile(reactor.doIteration)
def in_thread():
with LoggingContext("run"):

View File

@@ -252,11 +252,8 @@ class RoomMemberHandler(BaseHandler):
self.distributor.declare("user_joined_room")
self.distributor.declare("user_left_room")
@defer.inlineCallbacks
def get_room_members(self, room_id):
users = yield self.store.get_users_in_room(room_id)
defer.returnValue([UserID.from_string(u) for u in users])
return self.store.get_user_objs_in_room(room_id)
@defer.inlineCallbacks
def fetch_room_distributions_into(self, room_id, localusers=None,

View File

@@ -128,6 +128,7 @@ class EventsStore(SQLBaseStore):
txn.call_after(self.get_current_state_for_key.invalidate_all)
txn.call_after(self.get_rooms_for_user.invalidate_all)
txn.call_after(self.get_users_in_room.invalidate, event.room_id)
txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id)
txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id)
txn.call_after(self.get_room_name_and_aliases, event.room_id)

View File

@@ -67,6 +67,7 @@ class RoomMemberStore(SQLBaseStore):
txn.call_after(self.get_rooms_for_user.invalidate, target_user_id)
txn.call_after(self.get_joined_hosts_for_room.invalidate, event.room_id)
txn.call_after(self.get_users_in_room.invalidate, event.room_id)
txn.call_after(self.get_user_objs_in_room.invalidate, event.room_id)
def get_room_member(self, user_id, room_id):
"""Retrieve the current state of a room member.
@@ -101,6 +102,12 @@ class RoomMemberStore(SQLBaseStore):
return [r["user_id"] for r in rows]
return self.runInteraction("get_users_in_room", f)
@cached()
def get_user_objs_in_room(self, room_id):
return self.get_users_in_room(room_id).addCallback(
lambda users: [UserID.from_string(u) for u in users]
)
def get_room_members(self, room_id, membership=None):
"""Retrieve the current room member list for a room.