It seems that I somewhat over-engineered my queue :-) I don't know any Java
so this is very helpful!

If I want to know the result of the email send within the worker
thread, would you recommend sending it back through a channel?

One purpose of my queue was to be able to put urgent messages at the front
of the queue. I guess that using a threadpool with workers does not give me
any guarantee that the email is delivered immediately, since X emails may
already have been added but not yet sent. I guess that one one use a
dedicated thread(pool) for urgent messages?

Thanks,
Brjánn

On Thu, 25 Oct 2018 at 20:16, James Reeves <ja...@booleanknot.com> wrote:

> On Thu, 25 Oct 2018 at 19:01, <brj...@gmail.com> wrote:
>
>> Thank you for the thorough explanation! So if I understand you correctly,
>> if no calls are made to the executor thread, it will just rest silently
>> until queue-email is called again - not consuming any server resources.
>>
>
> That's essentially correct.
>
> Threads do take up a small amount of memory even when idle (IIRC its
> around 1M per thread), but unless you're dealing with thousands of threads
> or you're dealing with very constrained memory, this can be ignored.
> Creating a thread is relatively expensive, which is why they're often kept
> around for reuse in thread pools.
>
>
>> Are there any recommendations for the number of worker threads when each
>> does IO?
>>
>
> It depends entirely on the external service you're communicating with. My
> advice would be to choose a relatively small default, say 32 or under, and
> then make it configurable from an environment variable or system property.
> That way you can tune the service without changing the code.
>
> (def mail-pool-size
>   (Integer/parseInt (or (System/getenv "MAIL_POOL_SIZE") "32")))
>
> --
> James Reeves
> booleanknot.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to