Mercurial > p > roundup > code
annotate roundup/actions.py @ 6565:2c2dbfc332ba
Try to handle multiple connections better.
The session database is a hot spot. When multiple requests (e.g. 20)
come in at the same time session database contention can get great.
The original code didn't retry session database access when the open
failed. This resulted in errors at the client.
The second pass delayed 0.01 seconds and retried. It was better but we
still had multiple second stalls. I think the first request got in,
everybody else backed up and then retried at the same time. Again they
stepped on each other. With logging I would see many counters go all
the way to low single digits or to -1 indicating falure.
This pass uses randomint to generate delays from 0-.125 seconds in 5ms
increments. This performs better in testing. I rarely saw a counter
less than 13 (2 failed retries). Current logging starts after 6
failures and counts down until success or failure.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Thu, 16 Dec 2021 20:02:00 -0500 |
| parents | 48a1f919f894 |
| children | 4c9acc580769 |
| rev | line source |
|---|---|
| 4083 | 1 # |
| 2 # Copyright (C) 2009 Stefan Seefeld | |
| 3 # All rights reserved. | |
| 4 # For license terms see the file COPYING.txt. | |
| 5604 | 5 # Actions used in REST and XMLRPC APIs |
| 4083 | 6 # |
| 7 | |
|
5071
a7541077cf12
Remove 'import *' statement from actions.py
John Kristensen <john@jerrykan.com>
parents:
4357
diff
changeset
|
8 from roundup.exceptions import Unauthorised |
| 4083 | 9 from roundup import hyperdb |
| 6003 | 10 |
| 4083 | 11 |
| 12 class Action: | |
| 13 def __init__(self, db, translator): | |
| 14 self.db = db | |
| 15 self.translator = translator | |
| 16 | |
| 17 def handle(self, *args): | |
| 18 """Action handler procedure""" | |
| 19 raise NotImplementedError | |
| 20 | |
| 21 def execute(self, *args): | |
| 22 """Execute the action specified by this object.""" | |
| 23 | |
| 24 self.permission(*args) | |
| 25 return self.handle(*args) | |
| 26 | |
| 27 def permission(self, *args): | |
| 28 """Check whether the user has permission to execute this action. | |
| 29 | |
| 30 If not, raise Unauthorised.""" | |
| 31 | |
| 32 pass | |
| 33 | |
| 34 def gettext(self, msgid): | |
| 35 """Return the localized translation of msgid""" | |
| 36 return self.translator.gettext(msgid) | |
| 37 | |
| 38 _ = gettext | |
| 39 | |
| 40 | |
| 5604 | 41 class PermCheck(Action): |
| 42 def permission(self, designator): | |
| 43 | |
| 44 classname, itemid = hyperdb.splitDesignator(designator) | |
| 45 perm = self.db.security.hasPermission | |
| 46 | |
| 6003 | 47 if not perm('Retire', self.db.getuid(), classname=classname, |
| 48 itemid=itemid): | |
| 5604 | 49 raise Unauthorised(self._('You do not have permission to retire ' |
| 50 'or restore the %(classname)s class.') | |
| 6003 | 51 % locals()) |
| 52 | |
| 5604 | 53 |
| 54 class Retire(PermCheck): | |
| 4083 | 55 |
| 56 def handle(self, designator): | |
| 57 | |
| 58 classname, itemid = hyperdb.splitDesignator(designator) | |
| 59 | |
| 60 # make sure we don't try to retire admin or anonymous | |
| 61 if (classname == 'user' and | |
| 6003 | 62 self.db.user.get(itemid, 'username') in ('admin', 'anonymous')): |
|
4357
13b3155869e0
Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents:
4125
diff
changeset
|
63 raise ValueError(self._( |
|
13b3155869e0
Beginnings of a big code cleanup / modernisation to make 2to3 happy
Richard Jones <richard@users.sourceforge.net>
parents:
4125
diff
changeset
|
64 'You may not retire the admin or anonymous user')) |
| 4083 | 65 |
| 66 # do the retire | |
| 67 self.db.getclass(classname).retire(itemid) | |
| 68 self.db.commit() | |
| 69 | |
| 70 | |
| 5604 | 71 class Restore(PermCheck): |
| 72 | |
| 73 def handle(self, designator): | |
| 4083 | 74 |
| 75 classname, itemid = hyperdb.splitDesignator(designator) | |
| 76 | |
| 5604 | 77 # do the restore |
| 78 self.db.getclass(classname).restore(itemid) | |
| 79 self.db.commit() |
