-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
queue-manager -> queues, proper readme
- Loading branch information
Showing
5 changed files
with
73 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,5 @@ pom.xml.asc | |
*.class | ||
/.lein-* | ||
/.nrepl-port | ||
.DS_Store | ||
.DS_Store | ||
/doc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,64 @@ | ||
# durable-queue | ||
![](docs/EasterIsland.jpg) | ||
|
||
A Clojure library designed to ... well, that part is up to you. | ||
This library implements a disk-backed task queue, allowing for queues that can survive processes dying, and whose size are bounded by available disk rather than memory. | ||
|
||
## Usage | ||
### usage | ||
|
||
FIXME | ||
To interact with queues, first create a `queues` object by specifying a directory in the filesystem and an options map: | ||
|
||
## License | ||
```clj | ||
> (require '[durable-queue :refer :all]) | ||
nil | ||
> (def q (queues "/tmp" {})) | ||
#'q | ||
``` | ||
|
||
Copyright © 2013 FIXME | ||
This manager allows us to `put!` and `take!` tasks from named queues. `take!` is a blocking read, and will only return once a task is available or, if a timeout is defined (in milliseconds), once the timeout elapses: | ||
|
||
Distributed under the Eclipse Public License either version 1.0 or (at | ||
your option) any later version. | ||
```clj | ||
> (take! q :foo 10 :timed-out!) | ||
:timed-out! | ||
> (put! q :foo "a task") | ||
true | ||
> (take! q :foo) | ||
< :in-progress | "a task" > | ||
> (deref *1) | ||
"a task" | ||
``` | ||
|
||
Notice that the task has a value describing its progress, and a value describing the task itself. We can get the task descriptor by dereferencing the returned task. However, just because we've taken the task doesn't mean we've completed the action associated with it. In order to make sure the task isn't retried on restart, we must mark it as `complete!`. | ||
|
||
```clj | ||
> (put! q :foo "another task") | ||
true | ||
> (take! q :foo) | ||
< :in-progress | "another task" > | ||
> (complete! *1) | ||
true | ||
``` | ||
|
||
If our task fails and we want to re-enqueue it to be tried again, we can instead call `(retry! task)`. | ||
|
||
### configuring the queues | ||
|
||
The queue-manager can be given a number of different options, which can affect its performance and correctness. | ||
|
||
By default, the queue-manager assumes all tasks are idempotent. This is necessary, since the process can die at any time and leave an in-progress task in an undefined state. If your tasks are not idempotent, a `:complete?` predicate can be defined which, on instantiation of the queue-manager, will scan through all pre-existing task descriptors and remove those for which the predicate returns true. | ||
|
||
A complete list of options is as follows: | ||
|
||
| name | description | | ||
|------|-------------| | ||
| `:complete?` | a predicate for identifying already completed tasks, defaults to always returning false | | ||
| `:max-queue-size` | the maximum number of elements that can be in the queue before `put!` blocks | | ||
| `:slab-size` | The size, in bytes, of the backing files for the queue. Defaults to 16mb. | | ||
| `:fsync-put?` | Whether an fsync should be performed for each `put!`. Defaults to true. | | ||
| `:fsync-take?` | Whether an fsync should be performed for each `take!`. Defaults to false. | | ||
|
||
Disabling `:fsync-put?` will risk losing tasks if a process dies (though, depending on the hardware and underlying implementation of fsync, this may be possible regardless). Disabling `:fsync-take?` increases the chance of a task being re-run when a proces dies. Disabling both will increase throughput of the queue by an order of magnitude (~6k tasks/sec in the default configuration, ~100k tasks/sec with fsync completely disabled). Tradeoffs between these two can be made by batching tasks. | ||
|
||
### license | ||
|
||
Copyright © 2013 Factual Inc | ||
|
||
Distributed under the Eclipse Public License 1.0 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters