Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Deduplicate identical /sync requests #668

Merged
merged 3 commits into from Mar 24, 2016

Conversation

Projects
None yet
4 participants
Contributor

NegativeMjark commented Mar 24, 2016

If two /sync requests arrive at the server at the same time then use the same sync response for both of them.

@oddvar oddvar added the in progress label Mar 24, 2016

@ara4n ara4n commented on an outdated diff Mar 24, 2016

synapse/util/caches/response_cache.py
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from synapse.util.async import ObservableDeferred
+
+
+class ResponseCache(object):
+ """
+ This caches a deferred response. Until the deferred completes it will be
+ returned from the cache. This means that if the client retries the request
+ while the response is still being computed, that original response will be
+ used rather than trying to compute a new response.
+ """
+
+ def __init__(self):
+ self.pending_result_cache = {} # Request that haven't finished yet.
@ara4n

ara4n Mar 24, 2016

Owner

*Requests

Owner

ara4n commented Mar 24, 2016

this looks plausible to me, but i'm hardly a twisted expert.

@ara4n ara4n assigned NegativeMjark and unassigned ara4n Mar 24, 2016

NegativeMjark added some commits Mar 24, 2016

@NegativeMjark NegativeMjark merged commit 3e8bb99 into develop Mar 24, 2016

6 of 8 checks passed

Sytest Postgres (Commit) Build #214 origin/markjh/deduplicate in progress...
Details
Sytest Postgres (Merged PR) Build started sha1 is merged.
Details
Flake8 + Packaging (Commit) Build #211 origin/markjh/deduplicate succeeded in 28 sec
Details
Flake8 + Packaging (Merged PR) Build finished.
Details
Sytest SQLite (Commit) Build #215 origin/markjh/deduplicate succeeded in 4 min 22 sec
Details
Sytest SQLite (Merged PR) Build finished.
Details
Unit Tests (Commit) Build #256 origin/markjh/deduplicate succeeded in 1 min 11 sec
Details
Unit Tests (Merged PR) Build finished.
Details

@oddvar oddvar removed the in progress label Mar 24, 2016

@erikjohnston erikjohnston commented on the diff Mar 29, 2016

synapse/handlers/sync.py
@@ -35,6 +36,7 @@
"user",
"filter_collection",
"is_guest",
+ "request_key",
@erikjohnston

erikjohnston Mar 29, 2016

Owner

What is this?

@erikjohnston erikjohnston commented on the diff Mar 29, 2016

synapse/rest/client/v2_alpha/sync.py
@@ -115,6 +115,8 @@ def on_GET(self, request):
)
)
+ request_key = (user, timeout, since, filter_id, full_state)
@erikjohnston

erikjohnston Mar 29, 2016

Owner

I'm nervous about hard coding the query parameters that we care about, it feels like it would be too easy to forget to add them to the list. The failure mode of that is fairly terrible, too.

@richvdh richvdh deleted the markjh/deduplicate branch Dec 1, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment