Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mailwatch_milter_relay: very long execution time and high sql load #1265

Open
dneuhaeuser opened this issue Oct 30, 2022 · 5 comments
Open

Comments

@dneuhaeuser
Copy link
Contributor

dneuhaeuser commented Oct 30, 2022

When running 'mailwatch_milter_relay.php' I observed that a run with '--refresh' (e.g. via cron) takes longer and longer, rising while mail.log is growing, from several minutes ultimatively to hours.
In this time there are very high loads on the mysql process.

When looking at the script I ask myself whether the code from line 143 onward really needs to be executed for each and every line in the logfile (each execution of function 'process_entries').

// Scan queue for delivery attempts in queue and matching maillog entries

I believe it should probably be sufficient to run the codelines 143-163 only ONCE AFTER all logfile lines are processed.
All necessary informations for this are in the $idqueue array, right?

@shawniverson
Copy link
Member

Hi @dneuhaeuser That would make for a good optimization, I believe. This process has never been super efficient. I am open to ideas.

@dneuhaeuser
Copy link
Contributor Author

I'm currently working on improving this scripts performance...

On an installation with about ~500 emails in the mail.log (filesize ~2,5 MB)
running mailwatch_milter_relay currently takes 36 minutes here with 100% cpu load on mysqld.

@shawniverson
Copy link
Member

Just bear in mind under normal conditions --refresh should only be run once, preferrably after a logrotate even. I look forward to your improvements.

@dneuhaeuser
Copy link
Contributor Author

dneuhaeuser commented Nov 1, 2022

please look at the PR #1266

it is a very simple change but effective:
the execution which took 36+ minutes before now completes in about 10 seconds.

probably there is still room for more optimization...

the cron file ('tools/Postfix_relay/mailwatch-milter-relay') executes the script hourly with --refresh

EDIT: there is actually a suggestion for the 'tail' mode in 'INSTALL.milter'

if ps -C php -o args h | grep mailwatch_milter_relay.php

I wonder why this method is not used in the suggested cron-file

/usr/bin/php -q /usr/local/bin/mailwatch_milter_relay.php --refresh

@shawniverson
Copy link
Member

@dneuhaeuser you are right, we need to fix that discrepancy. I actually use a systemd unit for this. It may make even more sense for us to include both a cron with the tail method and a systemd unit file that also uses the tail method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants