Merge lp:~cmiller/desktopcouch/cpu-usage-replication into lp:desktopcouch

Proposed by Chad Miller
Status: Merged
Approved by: dobey
Approved revision: 282
Merged at revision: 279
Proposed branch: lp:~cmiller/desktopcouch/cpu-usage-replication
Merge into: lp:desktopcouch
Diff against target: 85 lines (+21/-1)
4 files modified
desktopcouch/application/plugins/tests/test_ubuntuone_pairing.py (+3/-0)
desktopcouch/application/plugins/ubuntuone_pairing.py (+13/-1)
desktopcouch/application/service.py (+1/-0)
desktopcouch/application/tests/test_service.py (+4/-0)
To merge this branch: bzr merge lp:~cmiller/desktopcouch/cpu-usage-replication
Reviewer Review Type Date Requested Status
dobey (community) Approve
Roman Yepishev (community) fieldtest Approve
Eric Casteleijn (community) Approve
Review via email: mp+68462@code.launchpad.net

Commit message

Slow down the idle-run function that checks for whether all the blocking semaphores are completed. gobject may call this every chance it gets, which pegs the CPU.

Catch the signal from the service that indicates no response is ever coming, CredentialsNotFound. Don't wait for timeout. Also, in cases where there is no response from the ubuntu-sso client, continue with execution. A dbus method call is waiting on us to complete, probably. desktopcouch can operate without ubuntuone support, so we shouldn't deny it from running altogether.

To post a comment you must log in.
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good.

review: Approve
Revision history for this message
Roman Yepishev (rye) wrote :

During my tests it takes 20 seconds to start replying to the dbus getPort() even when all the databases are already in disk cache. Could you please check whether this is happening on your installation too?

review: Needs Information (fieldtest)
Revision history for this message
Roman Yepishev (rye) wrote :

Looks awesome!

review: Approve (fieldtest)
Revision history for this message
dobey (dobey) wrote :

56 +
57 + gobject.timeout_add(TIMEOUT_SEC*1000, blocking_semaphores.discard,
58 + PLUGIN_NAME)

You should drop the *1000 here and use timeout_add_seconds() instead. Using add_seconds instead, results in timeouts getting aligned, so that number of wakeups is reduced.

review: Needs Fixing
Revision history for this message
dobey (dobey) :
review: Approve
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'desktopcouch/application/plugins/tests/test_ubuntuone_pairing.py'
2--- desktopcouch/application/plugins/tests/test_ubuntuone_pairing.py 2011-04-15 21:43:34 +0000
3+++ desktopcouch/application/plugins/tests/test_ubuntuone_pairing.py 2011-07-21 14:41:34 +0000
4@@ -169,6 +169,9 @@
5
6 iface = ubuntu_sso.DBUS_CREDENTIALS_IFACE
7 bus.add_signal_receiver(handler_function=ANY,
8+ signal_name='CredentialsNotFound',
9+ dbus_interface=iface)
10+ bus.add_signal_receiver(handler_function=ANY,
11 signal_name='CredentialsFound',
12 dbus_interface=iface)
13
14
15=== modified file 'desktopcouch/application/plugins/ubuntuone_pairing.py'
16--- desktopcouch/application/plugins/ubuntuone_pairing.py 2011-04-14 02:55:00 +0000
17+++ desktopcouch/application/plugins/ubuntuone_pairing.py 2011-07-21 14:41:34 +0000
18@@ -24,6 +24,7 @@
19 from desktopcouch.application.server import DesktopDatabase
20 from ubuntuone.clientdefs import APP_NAME
21
22+TIMEOUT_SEC = 20
23 PLUGIN_NAME = __name__
24 U1_PAIR_RECORD = "ubuntu_one_pair_record"
25 MAP_JS = """function(doc) {
26@@ -33,7 +34,6 @@
27 }
28 """
29
30-
31 def pair_with_ubuntuone(couchdb_port, blocking_semaphores,
32 management_db=None,
33 db_class=DesktopDatabase,
34@@ -95,8 +95,17 @@
35 receiver = lambda *args: \
36 got_new_credentials(couchdb_port, blocking_semaphores,
37 *args)
38+ def abort_getting_credentials(*args):
39+ """Log and remove our semaphore."""
40+ logging.warn("Credentials not found for ubuntuone.")
41+ blocking_semaphores.discard(PLUGIN_NAME)
42
43 iface = ubuntu_sso.DBUS_CREDENTIALS_IFACE
44+
45+ bus.add_signal_receiver(handler_function=abort_getting_credentials,
46+ signal_name='CredentialsNotFound',
47+ dbus_interface=iface)
48+
49 bus.add_signal_receiver(handler_function=receiver,
50 signal_name='CredentialsFound',
51 dbus_interface=iface)
52@@ -125,3 +134,6 @@
53 blocking_semaphores.add(PLUGIN_NAME)
54
55 gobject.idle_add(listen_to_dbus, couchdb_port, blocking_semaphores)
56+
57+ gobject.timeout_add_seconds(TIMEOUT_SEC, blocking_semaphores.discard,
58+ PLUGIN_NAME)
59
60=== modified file 'desktopcouch/application/service.py'
61--- desktopcouch/application/service.py 2011-07-20 20:35:43 +0000
62+++ desktopcouch/application/service.py 2011-07-21 14:41:34 +0000
63@@ -122,6 +122,7 @@
64 func, *args, **kwargs):
65 """Run a function if no semaphores exist, else try later."""
66 if blocking_semaphores:
67+ self._sleep(0.2) # Never peg the CPU
68 return True # Make idle call try us again.
69 else:
70 func(*args, **kwargs)
71
72=== modified file 'desktopcouch/application/tests/test_service.py'
73--- desktopcouch/application/tests/test_service.py 2011-04-25 16:46:35 +0000
74+++ desktopcouch/application/tests/test_service.py 2011-07-21 14:41:34 +0000
75@@ -82,6 +82,10 @@
76 self._mainloop.stop # pylint: disable=W0104
77 self.mocker.result(ANY)
78
79+ semaphores.discard # pylint: disable=W0104
80+ self.mocker.result("disc")
81+ self._gobject.timeout_add_seconds(ANY, "disc", ANY)
82+
83 self._gobject.idle_add(ANY, self._port_result, semaphores)
84 self._gobject.idle_add(ANY, semaphores, self._advertiser, ANY,
85 self._ctx)

Subscribers

People subscribed via source and target branches