Note that there are some explanatory texts on larger screens.

plurals
  1. PODisk-backed array in Go
    primarykey
    data
    text
    <p>How can I create a disk-based delayed queue in Go?</p> <p>I am writing a Go program to take certain actions on data after certain time intervals. Here is a stripped down version.</p> <pre><code>func IncomingJob (data MyStruct) { //Run immediately dosomething(&amp;data, 1) time.Sleep(5 * time.Minute) //Run after 5 minutes has passed from initial arrival dosomething(&amp;data, 2) time.Sleep(5 * time.Minute) //Run after 10 minutes has passed from initial arrival dosomething(&amp;data, 3) time.Sleep(50 * time.Minute) //Run after 60 minutes has passed from initial arrival dosomething(&amp;data, 4) } </code></pre> <p>This func would be initialized as a goroutinue.</p> <pre><code>go IncomingJob(data) </code></pre> <p>The problem I am having is that each instance of IncomingJob runs for 60 minutes and the <code>MyStruct</code> object stays in memory for that duration. The total memory usage is pretty huge. If I want to support 1 million runs per hour, that means at any given time, there are 1 million <code>MyStruct</code> objects in memory waiting, doing nothing. I can use <code>time.AfterFunc</code> for this as well, but that doesn't change anything with respect to memory usage.</p> <p>Is there some disk backed FIFO queue/buffer implementation in Go? That way I could have 3 queues (for different intervals) and poll it and sleep until its the correct time for the polled data to be reprocessed. This way I would lose some CPU cycles in serialization, add I/O latency to an otherwise in-memory application but save a massive amount of memory. </p> <p>Update: <code>time.AfterFunc</code> uses a lot less memory.</p> <pre><code>func IncomingJob (data MyStruct) { //Run immediately dosomething(&amp;data, 1) time.AfterFunc(5 * time.Minute, func() { //Run after 5 minutes has passed from initial arrival dosomething(&amp;data, 2) time.AfterFunc(5 * time.Minute, func() { //Run after 10 minutes has passed from initial arrival dosomething(&amp;data, 3) }) time.AfterFunc(50 * time.Minute, func() { //Run after 50 minutes has passed from initial arrival dosomething(&amp;data, 4) }) }) } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload