From d8fa5e9099447b613737a048006bfab1c370d485 Mon Sep 17 00:00:00 2001 From: Neil Williams Date: Mon, 20 Aug 2012 00:09:03 -0700 Subject: [PATCH] tdb_sql: Collect stats on wasted UPDATEs in data prop storage. This will give us better data on which tables will prefer to SELECT and INSERT and which will prefer to optimistically UPDATE. --- r2/r2/lib/db/tdb_sql.py | 2 ++ r2/r2/lib/db/thing.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/r2/r2/lib/db/tdb_sql.py b/r2/r2/lib/db/tdb_sql.py index abf919ff1..29c885784 100644 --- a/r2/r2/lib/db/tdb_sql.py +++ b/r2/r2/lib/db/tdb_sql.py @@ -508,6 +508,8 @@ def set_data(table, thing_id, **vals): i = table.insert(values = dict(thing_id = thing_id)) i.execute(*inserts) + return len(inserts) + def incr_data_prop(table, type_id, thing_id, prop, amount): t = table transactions.add_engine(t.bind) diff --git a/r2/r2/lib/db/thing.py b/r2/r2/lib/db/thing.py index d8b446011..ff74b747e 100644 --- a/r2/r2/lib/db/thing.py +++ b/r2/r2/lib/db/thing.py @@ -257,7 +257,11 @@ class DataThing(object): data_props[k] = v if data_props: - self._set_data(self._type_id, self._id, **data_props) + useless_updates = self._set_data(self._type_id, + self._id, + **data_props) + else: + useless_updates = 0 if thing_props: self._set_props(self._type_id, self._id, **thing_props) @@ -271,6 +275,18 @@ class DataThing(object): self._cache_myself() + thing_or_rel = "thing" if self._type_prefix == "t" else "rel" + + if useless_updates: + g.stats.simple_event("%s.useless_updates.%s" % (thing_or_rel, + self._type_name), + useless_updates) + if data_props: + g.stats.simple_event("%s.data_props.%s" % (thing_or_rel, + self._type_name), + len(data_props)) + + @classmethod def _load_multi(cls, need): need = tup(need)