Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZAnS7-0000hG-4O for pgsql-jdbc@arkaria.postgresql.org; Thu, 02 Jul 2015 22:59:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZAnS5-0007P9-R8 for pgsql-jdbc@arkaria.postgresql.org; Thu, 02 Jul 2015 22:59:29 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZAnEQ-0006HD-4W for pgsql-jdbc@postgresql.org; Thu, 02 Jul 2015 22:45:22 +0000 Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZAnED-0000bw-G6 for pgsql-jdbc@postgresql.org; Thu, 02 Jul 2015 22:45:20 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ZAnE8-0001DU-WC for pgsql-jdbc@postgresql.org; Fri, 03 Jul 2015 00:45:05 +0200 Received: from 142-254-34-190.dsl.dynamic.sonic.net ([142.254.34.190]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Jul 2015 00:45:04 +0200 Received: from ben.manes by 142-254-34-190.dsl.dynamic.sonic.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 03 Jul 2015 00:45:04 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-jdbc@postgresql.org From: Ben Manes Subject: Re: Adding new dependencies for in-core Date: Thu, 2 Jul 2015 22:26:09 +0000 (UTC) Lines: 31 Message-ID: References: <011501d0b357$26f1eca0$74d5c5e0$@eu> <3A641C7E-04D2-4554-8CDC-37A11E0178AB@gmail.com> <013001d0b35e$253ae9a0$6fb0bce0$@eu> <0DC27A9D-1556-427B-91FF-4D4FBD1F52E2@gmail.com> <6BD778EF-0D5A-4293-8A08-723903A5FB44@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: sea.gmane.org User-Agent: Loom/3.14 (http://gmane.org/) X-Loom-IP: 142.254.34.190 (Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36) X-Pg-Spam-Score: -2.0 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Steven Schlansker gmail.com> writes: > On Jun 30, 2015, at 11:14 AM, Vladimir Sitnikov wrote: > > Final note, is a ConcurrentLinkedHashMap actually the data structure we > should be using? The "linked" part enforces that the removal strategy is > not LRU, it is actually FIFO. So an incoming query may evict the oldest > entry, which could very well be the most used entry. Maybe this is not a > problem in practice but I thought I'd point it out. CLHM evicts by LRU. Java's LinkedHashMap may be configured in either insertion order (FIFO) or access order (LRU). The concurrent version provides only the access order as it is intended to be used as a cache. So the eviction is smart, as much as an LRU can be. CLHM is really easy to shade (as many do), fork (as some do), and is pretty tiny. An LRU policy is surprisingly tricky to implement fully concurrently, because every read is in fact a write. This is solved by borrowing an idea from Postgres - the write ahead log. The reads are recorded cheaply and replayed in batches so that reads and writes may operate concurrently. The successor project, Caffeine, includes a design document that describes a similar approach, with some additional optimizations. Also see the benchmarks. That cache is heavier (JAR size) due to providing a richer feature set. Cheers, Ben (author) https://github.com/ben-manes/caffeine/wiki/Design https://github.com/ben-manes/caffeine/wiki/Benchmarks -- Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc