Open sezaru opened 4 years ago
Hey @sezaru,
Can you give me a bit more information about what your use case is? I just want to make sure this isn't an XY problem. :)
I try to steer clear of :infinity
waits in blocking calls, since that means that the caller isn't able to respond to any system/debug messages, and its mailbox can fill up.
Sure.
So, I created a fork of the built-in mnesia queue to do 2 things, one is to add a priority parameter to the key so the queue would handle some prioritized jobs before others. And I also changed the mnesia calls to be sync_transaction
since I need to guarantee that they are indeed persisted to the disk and also to avoid mnesia overload
messages.
The main issue here is probably the sync_transaction
, since every write to the disk will follow a sync call that can take some time if the harddrive is overloaded (which it is in my case), That means that, for example, the enqueue call will timeout sometimes.
If :infinity
is not ok, can we bump the timeout time then?
Or maybe some way to allow the user to specify the timeout he desires, this is probably the best solution IMO, but I didn't see an easy way to do that in every part of the code that contains a GenServer.call
unless using a config, something like:
config :honeydew, timeout: 10_000
For completeness, I'm pasting my custom mnesia queue bellow (note that I didn't add the Priorities
module since I can't disclosure it, but the Priorities.priority!
function just returns an integer with the priority of the job I want.)
Are you running a multi-node mnesia cluster? I ask because ensuring that a job is written to disk on a single-node cluster isn't a lot of assurance that you'll have continuity of service if that disk dies.
I'm guessing that you're using a single node, since honeydew will automatically use the :sync_transaction
access context when the table is replicated to multiple nodes.
If that's the case, I believe that :async_dirty
is the right choice. If I've properly understood mnesia's access contexts, the "dirty" part is fine, because there's only one queue process accessing the table, hence no need for transaction isolation overhead. The "async" part is fine, because the synchronicity that it's referring to is that it'll block until other nodes in the cluster have executed the operation, "async" in a single node context still waits for the operation to be completed locally. So I :async_dirty
will still block while it write to a single-node's disk.
I'd really prefer not to mess with the messaging timeouts, five seconds is a really long time as it is. If you're waiting five seconds on a single job write, then you're probably doing so much traffic that you're going to be backing up the queue's mailbox into memory. Having that backpressure is really important, it prevents overloads from becoming systemic catastrophes. How big are your job parameters? Are you enqueuing very large binaries?
At the moment, the mnesia queue is only intended to be run in a single process throughout the entire cluster, so that usage of :unique_integer
is safe (unless I'm missing something). That being said, I'm honestly not pleased with the mnesia queue's distribution story, I'm in the middle of the slow and grueling process of replacing it with a better implementation.
I quite like your priority implementation, I'll have to steal that at some point. :)
Sorry for taking a while to reply.
Are you running a multi-node mnesia cluster?
No, I'm running just a single node for mnesia.
So I :async_dirty will still block while it write to a single-node's disk.
Oh! I didn't know that! I guessed that the dirty functions didn't guarantee disk write. Nice!
How big are your job parameters? Are you enqueuing very large binaries?
Nah, the jobs are very small, it is a job to send notifications to my app via FCM, so their payload needs to be always less than 4kb anyway.
I think the issue is that other parts of the system are loading and thrashing the disk so much that sometimes everything hangs for some time (my guess is that I fill my SSD cache, so it needs to dump it to disk and this gives very bad disk performance for some time).
But the major issue I see is that I will receive the timeout error, but the job call will still finish correctly, for my case, this means that the job will be added to the queue, I will receive a timeout, meaning that the system will retry to add the job, adding a duplicated one.
Since my jobs are notifications to users of my app, this means that they would receive duplicated notifications, which is bad, that's why for my case I prefer to hang there and wait then simply timeout and not be sure if the message went through or not.
I quite like your priority implementation, I'll have to steal that at some point. :)
haha thanks. One issue with it is that I cannot send a custom argument to the job queue when adding a new job, so I did a workaround by adding a new, unused argument to the function I want to run with the priority of that job and I retrieve it from the job struct during job queue. If priority queue is something in the roadmap, maybe a way to add a custom value to the job async function would be great (If it is not clear what I meant, I can open a new issue to explain that better so it doesn't bloat this issue with too much off-topic).
Hello, I created a custom mnesia queue that do some specific things to my use case.
The issue is that my queue is slower than the built-in mnesia queue, so sometimes it takes more than 5 seconds to queue a new job, making
GenServer.call(queue_process, {:enqueue, job})
timeout and crash.The obvious solution to that is to bump the timeout value, but there is no way to configure that inside Honeydew.
I tried creating a fork and seeing if there is an easy way to pass the timeout value to all
Genserver
calls, but it doesn't seem to be an easy way to do that since these functions can be called in so many places.For me, an easy fix would be to simply change the default of all the calls to use
:infinity
as timeout since it is pretty safe and only creates a problem if you have a deadlock, but I'm not sure if that is ok for you.Do you have any suggestion?