[
https://issues.apache.org/jira/browse/HTTPCLIENT-1165?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18083421#comment-18083421
]
ASF subversion and git services commented on HTTPCLIENT-1165:
-------------------------------------------------------------
Commit b6dab493cb37306e719f0069420ea037e54d5bd0 in httpcomponents-client's
branch refs/heads/master from Arturo Bernal
[ https://gitbox.apache.org/repos/asf?p=httpcomponents-client.git;h=b6dab493c ]
HTTPCLIENT-1165: Add optional async cache request collapsing
Coalesce concurrent cacheable async requests for the same cache key so that
only one backend request is executed on a cold miss. Waiting requests re-check
the cache after the leader completes.
Request collapsing is disabled by default and scoped to each caching executor.
> Cache allows multipe requests to retrieve the same cacheable resource from
> the server in multithreaded environment due to lack of proper locking
> ------------------------------------------------------------------------------------------------------------------------------------------------
>
> Key: HTTPCLIENT-1165
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1165
> Project: HttpComponents HttpClient
> Issue Type: Improvement
> Components: HttpCache
> Reporter: Manish Tripathi
> Priority: Major
> Labels: stuck, volunteers-wanted
> Fix For: Stuck
>
> Time Spent: 1h
> Remaining Estimate: 0h
>
> Consider the following scenario:
> Two separate threads are launched at the same time with identical Http
> requests through CachingHttpClient.
> Both threads look up the same URI in the cache at [almost] the same time and
> find no cached response for that URI.
> Both threads fall back to backend HttpClient and make identical requests to
> the server.
> Both threads retrieve the resource and attempt to store it in the cache.
> The same resource gets retrieved from the server twice and is stored in the
> cache twice.
> Obviously, the described algorithm is inefficient
> Suggested fix: introduce read-write locking mechanism which would block
> multiple requests to retrieve the same URI until one of the concurrent
> requests has either received a response header indicating that the response
> is not cacheable, or until cacheable response has been fully retrieved and
> stored in the cache. The proposed pseudo-code follows:
> cachingClient.execute(url) {
> if (lock_count(url)>0)
> lock=lockingFactory.acquireReadLock(url);
> else
> lock=lockingFactory.acquireWriteLock(url);
> response=satisfyFromCache(url);
> if (response==null) {
> if (lock.isReadLock()) { lock.release();
> lock=lockingFactory.acquireWriteLock(url); }
> response=satisfyFromServerAndStoreInCache(url);
> }
> lock.release();
> return response;
> }
> where lockingFactory instance is shared by multiple instances of
> CachingHttpClient.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]