forked from mozilla/zamboni
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cron + task for updating addon slowness (bug 615391)
- Loading branch information
Jeff Balogh
committed
Dec 4, 2010
1 parent
c436c9b
commit 3e454d4
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from django.db import connections | ||
|
||
import cronjobs | ||
import multidb | ||
from celery.messaging import establish_connection | ||
|
||
from amo.utils import chunked | ||
from . import tasks | ||
|
||
|
||
@cronjobs.register | ||
def update_perf(): | ||
cursor = connections[multidb.get_slave()].cursor() | ||
# The baseline is where addon_id is null. | ||
cursor.execute( | ||
"SELECT AVG(average) FROM perf_results WHERE addon_id IS NULL") | ||
baseline = cursor.fetchone()[0] | ||
|
||
# The perf_results table is a mess right now, so pull out one row | ||
# for each addon by finding the MAX(created) and then the AVG(average) | ||
# since there are many rows with the same (addon, created). | ||
# This scheme completely ignores app, os, and test. | ||
cursor.execute(""" | ||
SELECT J.addon_id, AVG(average) av FROM perf_results P INNER JOIN | ||
(SELECT addon_id, MAX(created) c FROM perf_results | ||
GROUP BY addon_id) J | ||
ON ((P.addon_id=J.addon_id) AND P.created=J.c) | ||
WHERE test='ts' | ||
GROUP BY P.addon_id | ||
HAVING av > %s""", (baseline,)) | ||
# A bunch of (addon, perf_average) pairs. | ||
perf = cursor.fetchall() | ||
with establish_connection() as conn: | ||
for chunk in chunked(perf, 25): | ||
tasks.update_perf.apply_async(args=[baseline, chunk], | ||
connection=conn) | ||
cursor.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import logging | ||
|
||
from celeryutils import task | ||
|
||
from addons.models import Addon | ||
|
||
log = logging.getLogger('z.perf.task') | ||
|
||
|
||
@task(rate_limit='1/s') | ||
def update_perf(baseline, perf, **kw): | ||
log.info('[%s@%s] Updating perf' % | ||
(len(perf), update_perf.rate_limit)) | ||
for addon, avg in perf: | ||
num = (avg - baseline) / baseline | ||
Addon.objects.filter(pk=addon).update(ts_slowness=100 * num) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE INDEX addon_created_idx ON perf_results (addon_id, created); | ||
|
||
ALTER TABLE addons | ||
ADD COLUMN ts_slowness FLOAT NULL; | ||
|
||
CREATE INDEX ts_slowness_idx ON addons (ts_slowness); |