sampart / WhiteOctoberSwiftMailerDBBundle

A bundle to facilitate SwiftMailer spooling messages to a database
31 stars 18 forks source link

queueMessage speed is too low #17

Open malas opened 8 years ago

malas commented 8 years ago

In DatabaseSpool::queueMessage do not use

$this->em->flush();

for every message as it drops down performance significantly. Flush should be called from the invoking code (externally):

foreach($messages as $message) {
  $this->getContainer()->get('mailer')->send($message);
}
$this->em->flush();
dfridrich commented 8 years ago

I'd better use flush() in every loop to prevent issues when app stops unexpectedly. If it would flush() after loop, it would send again and again email which have been sent already.

:-1:

malas commented 8 years ago

You can catch exceptions and delay/remove the message which causes it from resending it.

an option not to make SQL transaction after EVERY message would be a truly better way. Just try to send 1000 messages in one loop and check how much time the flushes consume in comparison with generating message content. no more comments would be needed.

aistis- commented 8 years ago

Run into the same problem.

richsage commented 8 years ago

I've started a branch here but won't have time in the next few days to look at it in depth. It marks emails as FAILED. This is very rough & ready code so far :-)

malas commented 8 years ago

@richsage sorry, but how this helps our problem? :)

there is an obvious architecture issue when working with emails and DB. Handling failed emails is a different problem. When working with batch emails it is a blocker.

richsage commented 8 years ago

If an email fails during the send process, your options would be:

The last option is what happens currently. The middle option is what I have started in my branch.

@malas if you are able to open a PR with your suggested approach, I will happily review but at the moment I don't currently have capacity to work on this change.

aistis- commented 8 years ago

What if use DBAL instead of entities? It would give a better performance.

malas commented 8 years ago

@aistis- could you explain more? how we could control the flush moment when using DBAL?

@richsage i will try to make one in some freeish weekend :)

aistis- commented 8 years ago

@malas depends on flushing strategy:

The idea would be to avoid using EntityManager::flush() as it flushes all other entities, despite you want it or not :confused:

sampart commented 7 years ago

The idea would be to avoid using EntityManager::flush() as it flushes all other entities, despite you want it or not :confused:

You can change this behaviour thanks to https://github.com/whiteoctober/WhiteOctoberSwiftMailerDBBundle/pull/21 (although that's not in a release yet - if anyone needs it, do shout).