| From: | Pawel Veselov <pawel(dot)veselov(at)gmail(dot)com> |
|---|---|
| To: | pgsql-jdbc(at)lists(dot)postgresql(dot)org |
| Subject: | Memory Consumption |
| Date: | 2021-12-21 20:23:33 |
| Message-ID: | CAMnJ+BdOs7hbbSkoL1+OeqkWbyRDXk30zEAw8eVhq7kqaJ5-bA@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-jdbc |
Hello.
I was examining some heap dumps, and noticed that Postgres connections
take quite a big bite out of the heap.
Out of the largest consumers within:
If a connection is used once, it carries a TypeInfoCache, which is ~20K.
For active connections, there is a QueryExectorImpl, that's sized
depending on the usage, for me it's ~180K per connection. The biggest
groups within each connections are:
* LRU query cache - 84K
* not in LRU (borrowed, evicted?) cached queries, ~18 items totalling ~52K
* PGStream, ~35K, which is really made up of ~4 8K buffers (for
streams and encoders)
Probably not much can be done about streams. But about 60% of a cached
query size is taken up by instances of Field objects. For a total of
2,170 queries there are 54K Field instances.
I understand the efforts required to make things cache for multiple
connections are probably not worth the memory savings, considering.
But I think the instances of Field can be at least cached per
connection, as they are bound to be the same.
I'm also concerned about the query cache size. The LRU cache has a
byte size limit which works as long as CachedQuery returns a realistic
size value from getSize(). However, it looks like that only checks the
size of the key, and a fixed overhead. The size of the underlying
query is ignored all together, but considering all the attached
Field[] instances it's not at all negligible. In my case there 3,405
queries with ~3M retain heap in keys, and ~10M in SimpleQuery
instances. But the formula returns 2*key size as the estimate, which
underestimates the size of the cached items by about 40% (in my case,
I think it will vary wildly).
--
With best of best regards
Pawel S. Veselov
| Attachment | Content-Type | Size |
|---|---|---|
| MAT.txt | text/plain | 10.8 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dave Cramer | 2021-12-23 13:30:28 | [pgjdbc/pgjdbc] 021403: log4jmessage (#2370) |
| Previous Message | Dave Cramer | 2021-12-20 14:30:21 | [pgjdbc/pgjdbc] 06cecb: Removed unsafe package and native kerberos ticket ... |