|
1 | 1 | # Async::Container |
2 | 2 |
|
3 | | -Provides containers which implement concurrency policy for high-level servers (and potentially clients). |
| 3 | +Provides containers which implement parallelism for clients and servers. |
4 | 4 |
|
5 | 5 | [](https://github.com/socketry/async-container/actions?workflow=Development) |
6 | 6 |
|
7 | | -## Installation |
| 7 | +## Features |
8 | 8 |
|
9 | | -``` bash |
10 | | -$ bundle add async-container |
11 | | -``` |
| 9 | +- Supports multi-process, multi-thread and hybrid containers. |
| 10 | +- Automatic scalability based on physical hardware. |
| 11 | +- Direct integration with [systemd](https://www.freedesktop.org/software/systemd/man/sd_notify.html) using `$NOTIFY_SOCKET`. |
| 12 | +- Internal process readiness protocol for handling state changes. |
| 13 | +- Automatic restart of failed processes. |
12 | 14 |
|
13 | 15 | ## Usage |
14 | 16 |
|
15 | | -### Container |
16 | | - |
17 | | -A container represents a set of child processes (or threads) which are doing work for you. |
18 | | - |
19 | | -``` ruby |
20 | | -require 'async/container' |
21 | | - |
22 | | -Async.logger.debug! |
23 | | - |
24 | | -container = Async::Container.new |
25 | | - |
26 | | -container.async do |task| |
27 | | - task.logger.debug "Sleeping..." |
28 | | - task.sleep(1) |
29 | | - task.logger.debug "Waking up!" |
30 | | -end |
31 | | - |
32 | | -Async.logger.debug "Waiting for container..." |
33 | | -container.wait |
34 | | -Async.logger.debug "Finished." |
35 | | -``` |
36 | | - |
37 | | -### Controller |
38 | | - |
39 | | -The controller provides the life-cycle management for one or more containers of processes. It provides behaviour like starting, restarting, reloading and stopping. You can see some [example implementations in Falcon](https://github.com/socketry/falcon/blob/master/lib/falcon/controller/). If the process running the controller receives `SIGHUP` it will recreate the container gracefully. |
40 | | - |
41 | | -``` ruby |
42 | | -require 'async/container' |
43 | | - |
44 | | -Async.logger.debug! |
45 | | - |
46 | | -class Controller < Async::Container::Controller |
47 | | - def setup(container) |
48 | | - container.async do |task| |
49 | | - while true |
50 | | - Async.logger.debug("Sleeping...") |
51 | | - task.sleep(1) |
52 | | - end |
53 | | - end |
54 | | - end |
55 | | -end |
56 | | - |
57 | | -controller = Controller.new |
58 | | - |
59 | | -controller.run |
60 | | - |
61 | | -# If you send SIGHUP to this process, it will recreate the container. |
62 | | -``` |
63 | | - |
64 | | -### Signal Handling |
65 | | - |
66 | | -`SIGINT` is the interrupt signal. The terminal sends it to the foreground process when the user presses **ctrl-c**. The default behavior is to terminate the process, but it can be caught or ignored. The intention is to provide a mechanism for an orderly, graceful shutdown. |
67 | | - |
68 | | -`SIGQUIT` is the dump core signal. The terminal sends it to the foreground process when the user presses **ctrl-\\**. The default behavior is to terminate the process and dump core, but it can be caught or ignored. The intention is to provide a mechanism for the user to abort the process. You can look at `SIGINT` as "user-initiated happy termination" and `SIGQUIT` as "user-initiated unhappy termination." |
69 | | - |
70 | | -`SIGTERM` is the termination signal. The default behavior is to terminate the process, but it also can be caught or ignored. The intention is to kill the process, gracefully or not, but to first allow it a chance to cleanup. |
71 | | - |
72 | | -`SIGKILL` is the kill signal. The only behavior is to kill the process, immediately. As the process cannot catch the signal, it cannot cleanup, and thus this is a signal of last resort. |
73 | | - |
74 | | -`SIGSTOP` is the pause signal. The only behavior is to pause the process; the signal cannot be caught or ignored. The shell uses pausing (and its counterpart, resuming via `SIGCONT`) to implement job control. |
75 | | - |
76 | | -### Integration |
77 | | - |
78 | | -#### systemd |
79 | | - |
80 | | -Install a template file into `/etc/systemd/system/`: |
81 | | - |
82 | | -``` |
83 | | -# my-daemon.service |
84 | | -[Unit] |
85 | | -Description=My Daemon |
86 | | -AssertPathExists=/srv/ |
87 | | -
|
88 | | -[Service] |
89 | | -Type=notify |
90 | | -WorkingDirectory=/srv/my-daemon |
91 | | -ExecStart=bundle exec my-daemon |
92 | | -Nice=5 |
93 | | -
|
94 | | -[Install] |
95 | | -WantedBy=multi-user.target |
96 | | -``` |
| 17 | +Please see the [project documentation](https://socketry.github.io/async-container/). |
97 | 18 |
|
98 | 19 | ## Contributing |
99 | 20 |
|
100 | | -1. Fork it |
101 | | -2. Create your feature branch (`git checkout -b my-new-feature`) |
102 | | -3. Commit your changes (`git commit -am 'Add some feature'`) |
103 | | -4. Push to the branch (`git push origin my-new-feature`) |
104 | | -5. Create new Pull Request |
| 21 | +We welcome contributions to this project. |
105 | 22 |
|
106 | | -## License |
| 23 | +1. Fork it. |
| 24 | +2. Create your feature branch (`git checkout -b my-new-feature`). |
| 25 | +3. Commit your changes (`git commit -am 'Add some feature'`). |
| 26 | +4. Push to the branch (`git push origin my-new-feature`). |
| 27 | +5. Create new Pull Request. |
107 | 28 |
|
108 | | -Released under the MIT license. |
| 29 | +## License |
109 | 30 |
|
110 | | -Copyright, 2017, by [Samuel G. D. Williams](http://www.codeotaku.com/samuel-williams). |
| 31 | +Copyright, 2017, by [Samuel G. D. Williams](https://www.codeotaku.com). |
111 | 32 |
|
112 | 33 | Permission is hereby granted, free of charge, to any person obtaining a copy |
113 | 34 | of this software and associated documentation files (the "Software"), to deal |
|
0 commit comments