grosjo / fts-xapian

Dovecot FTS plugin based on Xapian
GNU Lesser General Public License v2.1
94 stars 20 forks source link

Memory usage goes up until OOM-killer kills doveadm #97

Closed nielspeen closed 2 years ago

nielspeen commented 3 years ago

The server has 6GB RAM of which approx 0.5GB is used by other processes.

fts-xapian is version 1.4.13.

Mailbox size is 2.2G.

Config:

plugin {

  fts = xapian
  fts_xapian = partial=2 full=20 verbose=2

  fts_autoindex = yes
  fts_enforced = yes

  fts_autoindex_exclude = \Trash

  # Index attachements
  #fts_decoder = decode2text

}

service indexer-worker {
  # Increase vsz_limit to 2GB or above.
  # Or 0 if you have rather large memory usable on your server, which is preferred for performance)
  vsz_limit = 2G
}

When running /usr/bin/doveadm -v fts optimize -A memory goes up quickly during the expunging process. Eventually output stops. (Always at the same UID=10165.)

While the output is stopped, dovadm is still running and memory usage continues to grow. Eventually the OOM-killer kicks in and kills doveadm.

doveadm(niels.peen@xxx.com): Info: FTS Xapian: Expunging UID=10163 '/var/vmail/xxx.com/niels.peen//Maildir/xapian-indexes/db_3f052c1163e45d61a1190000f0f6226a'
doveadm(niels.peen@xxx.com): Info: FTS Xapian: Expunging UID=10164 '/var/vmail/xxx.com/niels.peen//Maildir/xapian-indexes/db_3f052c1163e45d61a1190000f0f6226a'
doveadm(niels.peen@xxx.com): Info: FTS Xapian: Expunging UID=10165 '/var/vmail/xxx.com/niels.peen//Maildir/xapian-indexes/db_3f052c1163e45d61a1190000f0f6226a'
Killed

What can I do to reduce the memory usage? I've tried lowering the vsz_limit for the indexer-worker, but it seems to be ignored.

grosjo commented 3 years ago

@nielspeen Can you share the log before the few lines before getting killed ?

grosjo commented 3 years ago

(using the latest git for tracing the bug)

nielspeen commented 3 years ago

Please find the entire log attached. log.txt

grosjo commented 3 years ago

THank you Can you try again with latest git ?

nielspeen commented 3 years ago

It manages to continue a little longer now (3420 log lines vs 3323 in the previous one), but it still gets killed in the same way. Should I upload the new log?

grosjo commented 3 years ago

Can you kindly regenerate the log with the very latest git ?

nielspeen commented 3 years ago

New log attached. log.txt

nielspeen commented 3 years ago

The new debug info led me to try and raise XAPIAN_MIN_RAM.

When I set XAPIAN_MIN_RAM to 250L, it manages to keep the free mem around 100MB and the process completes normally:

doveadm(x.x@xxx.com): Warning: FTS Xapian: Free memory 119 MB vs 250 MB minimum
doveadm(x.x@xxx.com): Warning: FTS Xapian: Expunging with low memory (119 MB)-> Commiting on disk
doveadm(x.x@xxx.com): Info: FTS Xapian: Expunging (3a) UID=5363 (Free mem= 119 MB) '/var/vmail/xxx.com/x.x//Maildir/xapian-indexes/db_200d370a3add5d618e180000f0f6226a'
doveadm(x.x@xxx.com): Info: FTS Xapian: Expunging (3b) UID=5363 (Free mem= 119 MB) done
doveadm(x.x@xxx.com): Info: FTS Xapian: Expunging (5) '/var/vmail/xxx.com/x.x//Maildir/xapian-indexes/db_200d370a3add5d618e180000f0f6226a' done in 23.45 secs
doveadm(x.x@xxx.com): Info: FTS Xapian: Deinit /var/vmail/wanwire.com/x.x//Maildir/xapian-indexes)
doveadm(xx@xxx.com): Info: fts_backend_xapian_init : xapian
doveadm(xx@xxx.com): Info: FTS Xapian: Index path = /var/vmail/xxx.com/x//Maildir/xapian-indexes
doveadm(xx@xxx.com): Info: FTS Xapian: Starting with partial=2 full=20 verbose=2
doveadm(xx@xxx.com): Info: FTS Xapian: fts_backend_xapian_optimize '/var/vmail/xxx.com/x//Maildir/xapian-indexes'
doveadm(xx@xxx.com): Info: FTS Xapian: Deinit /var/vmail/xxx.com/x//Maildir/xapian-indexes)

Perhaps XAPIAN_MIN_RAM can be made configurable?

grosjo commented 2 years ago

Hi I added a "lowmemory" paramater (check latest git README,md)

nielspeen commented 2 years ago

Today's git seems to cause a lot of leaked events:

doveadm: Warning: Event 0x5563f3f2b740 leaked (parent=0x5563f3f2b330): mail-user.c:78
doveadm: Warning: Event 0x5563f3f2b330 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f4009ef0 leaked (parent=0x5563f3f4cf80): mail-index.c:67
doveadm: Warning: Event 0x5563f40096c0 leaked (parent=0x5563f3f4cf80): fs-api.c:32
doveadm: Warning: Event 0x5563f40092b0 leaked (parent=0x5563f3f4cf80): mail-storage.c:430
doveadm: Warning: Event 0x5563f3f4cf80 leaked (parent=0x5563f3f21f00): mail-user.c:78
doveadm: Warning: Event 0x5563f3f21f00 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f3f2d080 leaked (parent=0x5563f3f234f0): mail-index.c:67
doveadm: Warning: Event 0x5563f3f2c820 leaked (parent=0x5563f3f234f0): fs-api.c:32
doveadm: Warning: Event 0x5563f3f2c300 leaked (parent=0x5563f3f234f0): mail-storage.c:430
doveadm: Warning: Event 0x5563f3f234f0 leaked (parent=0x5563f3f4e1d0): mail-user.c:78
doveadm: Warning: Event 0x5563f3f4e1d0 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f3f24d20 leaked (parent=0x5563f3fd58b0): mail-index.c:67
doveadm: Warning: Event 0x5563f3f24620 leaked (parent=0x5563f3fd58b0): fs-api.c:32
doveadm: Warning: Event 0x5563f3f23e30 leaked (parent=0x5563f3fd58b0): mail-storage.c:430
doveadm: Warning: Event 0x5563f3fd58b0 leaked (parent=0x5563f3fd54a0): mail-user.c:78
doveadm: Warning: Event 0x5563f3fd54a0 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f3fd6df0 leaked (parent=0x5563f3fcc8a0): mail-index.c:67
doveadm: Warning: Event 0x5563f3fd65c0 leaked (parent=0x5563f3fcc8a0): fs-api.c:32
doveadm: Warning: Event 0x5563f3fd5dd0 leaked (parent=0x5563f3fcc8a0): mail-storage.c:430
doveadm: Warning: Event 0x5563f3fcc8a0 leaked (parent=0x5563f3f1c990): mail-user.c:78
doveadm: Warning: Event 0x5563f3f1c990 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f3f16a20 leaked (parent=0x5563f3fbb710): mail-index.c:67
doveadm: Warning: Event 0x5563f3f16210 leaked (parent=0x5563f3fbb710): fs-api.c:32
doveadm: Warning: Event 0x5563f3f15a20 leaked (parent=0x5563f3fbb710): mail-storage.c:430
doveadm: Warning: Event 0x5563f3fbb710 leaked (parent=0x5563f3fbbf20): mail-user.c:78
doveadm: Warning: Event 0x5563f3fbbf20 leaked (parent=(nil)): mail-storage-service.c:1359
doveadm: Warning: Event 0x5563f3f11dd0 leaked (parent=0x5563f3f048f0): mail-index.c:67
doveadm: Warning: Event 0x5563f3f114b0 leaked (parent=0x5563f3f048f0): fs-api.c:32
doveadm: Warning: Event 0x5563f3f10e10 leaked (parent=0x5563f3f048f0): mail-storage.c:430
doveadm: Warning: Event 0x5563f3f048f0 leaked (parent=0x5563f3f05cb0): mail-user.c:78
doveadm: Warning: Event 0x5563f3f05cb0 leaked (parent=(nil)): mail-storage-service.c:1359

Edit: I see you are already working on this in #99.

grosjo commented 2 years ago

yes, this latest "mirnor" version of dovecot introduced major changes without notice

@cmouse Can you help ?

grosjo commented 2 years ago

@nielspeen Besides those memory leaks from dovecot, is the initial issue resolved ?

cmouse commented 2 years ago

Dovecot api has not changed drastically. Using fts_mail_user_init/deinit has been there before, you just have gotten away omitting it so far. Those leaks go away once you use it correctly. You could look from fts_solr for example.

grosjo commented 2 years ago

@cmouse I added the code from Solr already, and this is when the leaks appears

What are those functions about ? and how to fix those leaks ?

Thank you

grosjo commented 2 years ago

https://github.com/grosjo/fts-xapian/blob/master/src/fts-xapian-plugin.c

cmouse commented 2 years ago

Compare to https://github.com/dovecot/core/blob/73b1ed4e82f88220e9383f28c924e8f8e50479d0/src/plugins/fts-solr/fts-solr-plugin.c#L71

it does not do same things

grosjo commented 2 years ago

I already copied paste the code basically. What is wrong in my code ? what is the actual purpose of these functions ?

cmouse commented 2 years ago

They initialize fts plugin. You are not calling the next function in chain, and you are not adding module context.

grosjo commented 2 years ago

Can you please be much more clear ? What is "module context" , what "function in chain" are you referring to ?

All these were not needed before , and it worked pretty welll.

cmouse commented 2 years ago

https://github.com/dovecot/core/blob/73b1ed4e82f88220e9383f28c924e8f8e50479d0/src/plugins/fts-solr/fts-solr-plugin.c#L76

https://github.com/dovecot/core/blob/73b1ed4e82f88220e9383f28c924e8f8e50479d0/src/plugins/fts-solr/fts-solr-plugin.c#L98

grosjo commented 2 years ago

@nielspeen Is this now solved ?

nielspeen commented 2 years ago

This is now solved. Thanks!