Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gm1Yr-0002zu-NW for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jan 2019 19:18:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gm1Yo-0000C5-NP for pgsql-hackers@arkaria.postgresql.org; Tue, 22 Jan 2019 19:18:10 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gm1Yo-00005m-8E for pgsql-hackers@lists.postgresql.org; Tue, 22 Jan 2019 19:18:10 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gm1Yg-0006N0-5J for pgsql-hackers@postgresql.org; Tue, 22 Jan 2019 19:18:08 +0000 Received: by mail-wm1-x329.google.com with SMTP id m22so15491968wml.3 for ; Tue, 22 Jan 2019 11:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=faA5WmYq/VB8Q3+GTkYyf9fxKkaulOi3xvBkDP2DPdc=; b=cmMxnXVvNUvSFuh3GcWl3G9Awx59o1ijw3MGk6FEt+eMG5qjduqgVefcM/urbktzuP VT9AgtRPcp4N2t5cMgskNvpkbgY4NvhGwP3XO/wkUOuHQYcX/99qXN2TW19kDWl/DopM H/vYo6t7uE4TdUH/Q7tR7uRv3RGrFMcK/XSDaSDm7sTaT8SWa1KWn05C9MeUWBPqFH/d S3U89H3M9X3CUrUw993g4aNzJdR7dkf2PKD1VH9RPgu/KSZ5Vn7KfEylm71jWjq+OZ/5 a65pPaOgjXxKGZn2sJ0AzVoAs7egITMT9kJNcBQzWES/aneolIb7raNnguqwRGTPuAmz zHMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=faA5WmYq/VB8Q3+GTkYyf9fxKkaulOi3xvBkDP2DPdc=; b=ucd/5+XMFa+MPrJ971fwXAAfQ/tWJDmzG0BzYnnV2pDkpiHSlKB+bUujgDNgDhAuTW lylMTVc1khoTVus/8A08rSJZ19Ed9y3DOg9Q6qDBJeE8a4m3Sdmjmt//m77NTzDaulno fGTu/dLdH5fhUDah1B0l8KXQ02xe/A+qQhe79DPmk+PxK2MAgFQDMhgXxQkPJuy52Kwp 653FZJkhJ1TeTZ9BkWNnlfmCWiPtwY0YoXFYY+xmdaXOEtC+4wuIweb0fk4mEoZTjWts JvjZVXsuXzE14kwM266N0i9mPjQ0vkKu1DD66ZE0AyekGka4TbTrxDsRcwaSmEO6WItw 3mhA== X-Gm-Message-State: AJcUukdw2AIa5SZdCFR5oEQNnY74VbHPYy+DJL1y/bHQqrYKxyJzj2Ia nYKydmBjf86YNkHeJNYNxjfKdkilA5249ZNjRJoC7CpCt1cO1Q8EbO7+MeqlQy8W315L5YrcydP URxbYhK1pwC9e5fDAJ3clk4hMAqcVuGEVvnc7muQ2cd8u9TH2Ay6KHXyevINqSIFvnfhIXAwjg3 lHQFY4kRKyrKo= X-Google-Smtp-Source: ALg8bN553CiG16qlqHgCHxA7HsB38Cr+UFkvVvHEzt8kL6q2tgDuoZcYMiBF/zSP29k0r5BVQ/MXGg== X-Received: by 2002:a1c:43:: with SMTP id 64mr5208466wma.72.1548184679224; Tue, 22 Jan 2019 11:17:59 -0800 (PST) Received: from [10.137.2.21] (static-84-42-175-93.net.upcbroadband.cz. [84.42.175.93]) by smtp.gmail.com with ESMTPSA id a1sm84317353wrw.76.2019.01.22.11.17.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 11:17:58 -0800 (PST) Subject: Re: [PROPOSAL] Shared Ispell dictionaries To: Arthur Zakirov Cc: Andres Freund , Robert Haas , Tom Lane , Pavel Stehule , pgsql-hackers References: <27296.1522078068@sss.pgh.pa.us> <20180327121954.GA12726@zakirov.localdomain> <20180516113631.GA29544@zakirov.localdomain> <20180614084015.GA12451@zakirov.localdomain> <20181001092204.GA5071@zakirov.localdomain> <68aaaff6-0efe-c14b-7aee-fb110bb97f69@2ndquadrant.com> <337f7a55-58b8-4fcc-a933-5e7799fa6882@postgrespro.ru> <42b1ded6-fd44-5975-77e4-72ada1f134a2@2ndquadrant.com> <20190120222121.ehistvcr4wsu2su5@alap3.anarazel.de> <95aea959-97a1-2ded-c881-eede4e5a1f0c@2ndquadrant.com> <5113daa6-b6e7-59f6-c4a8-96b5b81474fb@postgrespro.ru> From: Tomas Vondra Message-ID: <1932084f-167a-8893-be24-c4c06afe113b@2ndquadrant.com> Date: Tue, 22 Jan 2019 20:17:56 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 1/22/19 7:36 PM, Arthur Zakirov wrote: > пн, 21 янв. 2019 г. в 19:42, Arthur Zakirov : >> >> On 21.01.2019 17:56, Tomas Vondra wrote: >>> I wonder if we could devise some simple cache eviction policy. We don't >>> have any memory limit GUC anymore, but maybe we could use unload >>> dictionaries that were unused for sufficient amount of time (a couple of >>> minutes or so). Of course, the question is when exactly would it happen >>> (it seems far too expensive to invoke on each dict access, and it should >>> happen even when the dicts are not accessed at all). >> >> Yes, I thought about such feature too. Agree, it could be expensive >> since we need to scan pg_ts_dict table to get list of dictionaries (we >> can't scan dshash_table). >> >> I haven't a good solution yet. I just had a thought to return >> max_shared_dictionaries_size. Then we can unload dictionaries (and scan >> the pg_ts_dict table) that were accessed a lot time ago if we reached >> the size limit. >> We can't set exact size limit since we can't release the memory >> immediately. So max_shared_dictionaries_size can be renamed to >> shared_dictionaries_threshold. If it is equal to "0" then PostgreSQL has >> unlimited space for dictionaries. > > I want to propose to clean up segments during vacuum/autovacuum. I'm not > aware of the politics of cleaning up objects besides relations during > vacuum/autovacuum. Could be it a good idea? > I doubt that's a good idea, for a couple of reasons. For example, would it be bound to autovacuum on a particular object or would it happen as part of each vacuum run? If the dict cleanup happens only when vacuuming a particular object, then which one? If it happens on each autovacuum run, then that may easily be far too frequent (it essentially makes the cases with too frequent autovacuum runs even worse). But also what happens when there only minimal write activity and thus no regular autovacuum runs? Surely we should still do the dict cleanup. > Vacuum might unload dictionaries when total size of loaded dictionaries > exceeds a threshold. When it happens vacuum scans loaded dictionaries and > unloads (unpins segments and removes hash table entries) those dictionaries > which isn't mapped to any backend process (it happens because > dsm_pin_segment() is called) anymore. > Then why to bound that to autovacuum at all? Why not just make it part of loading the dictionary? > max_shared_dictionaries_size can be renamed to > shared_dictionaries_cleanup_threshold. > That really depends on what exactly the threshold does. If it only triggers cleanup but does not enforce maximum amount of memory used by dictionaries, then this name seems OK. If it ensures max amount of memory, the max_..._size name would be better. I think there are essentially two ways: (a) Define max amount of memory available for shared dictionarires, and come up with an eviction algorithm. This will be tricky, because when the frequently-used dictionaries need a bit more memory than the limit, this will result in trashing (evict+load over and over). (b) Define what "unused" means for dictionaries, and unload dictionaries that become unused. For example, we could track timestamp of the last time each dict was used, and decide that dictionaries unused for 5 or more minutes are unused. And evict those. The advantage of (b) is that it adopts automatically, more or less. When you have a bunch of frequently used dictionaries, the amount of shared memory increases. If you stop using them, it decreases after a while. And rarely used dicts won't force eviction of the frequently used ones. cheers -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services