In many cases where iocaine was using `unwrap()`, handle it gracefully,
and return a `Result` instead.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
There's no need to have `poison()`, `poison_root()`, and
`poison_path()`: it is enough to have one, and mark path as
`Option<Path<String>>`, and supply a default.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Attempt to explain how iocaine uses the sources listed therein, their
format, and give a few examples too.
Fixes#12.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Before, on a low-capacity system (such as a an inexpensive cloud host),
doing Markov-chain text generation was _extraordinarily_ slow, taking
half a second or more to produce a page, and if multiple requests came
in simultaneously they could easily swamp the capacity of such a system.
Most of the time was spent in the Words iterator, which did a bunch of
cloning of Strings in what the hot path.
This changes the Markov generator's internal representation - now, instead
of storing Strings, it stores index-pairs into a single shared String,
normalized so that all references to particular words are collapsed into
a single pair. This also means that the hash map is working with
fixed-size values, which can't hurt.
In addition, it does only one hash-map lookup per generated word in the
happy-path of not reaching the end of the chain.
The upshot of all this is that where it was taking a half-second or more
to generate a page, it now takes about 0.001 seconds.
On the downside, the initialization of WurstsalatGeneratorPro has become
rather less flexible. Before, you created one and then taught it various
strings, or gave it a list of paths to read and teach itself from. Now,
the _only_ way to create one is directly with a list of paths. Changing
this is possible, but it means `Substr` would have to learn to distinguish
which source data it came from, which would mean a likely 50% increase in
its size. It didn't seem worth it to preserve that capability, which
wasn't even being used.
Previously, metrics were behind a feature flag (which was enabled by
default), now it's always available, but still disabled by default.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
The new metric is there to help gauge iocaine's uptime, without relying
on an external collector like `systemd_exporter`.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Include the system name in the cross-built binary file, and put it under
`iocaine-binaries/latest`, rather than `iocaine/${{ version }}`, to
match how the container image is tagged. Releases will have their own
version.
Documentation updated to point to the new place.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Rather than cloning `Iocaine` (along with the markov chain & everything)
all over the place, declare it shared state behind an `Arc<Mutex>`. This
should reduce the amount of cloning done noticably.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
These are quite... simple, and cover little, but it's more than nothing!
While there, enable tests in the Nix package, so they're run in CI too.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Thanks to @redshiftltd for test driving the nginx setup, and providing
very valuable feedback & the updated configurations.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
With the previous nginx configuration, all requests that matched
`$badagent` were rewrote to `/ai`, without the original URL anywhere.
This resulted in `iocaine` only seeing `/ai`, and thus, every page ended
up being rendered the same.
The rewrite should take the original request URI into account, which is
what this patch does.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
Added a few words about compiling Iocaine, added a docker example with a
TOML configuration file (vs the existing environment variable-based
example), and collected a mistake describing the shape of
`IOCAINE__SOURCES__MARKOV`.
These together should largely address #2.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This rebuilds the templating so that the *content* is no longer
pre-generated, only the parameters. It is up to the template (and some
newly implemented helper functions) to construct the output from those.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>
This was originally an embedded string in Rust, which needed to escape
the quotation mark. The escaping is no longer needed in raw HBS.
Signed-off-by: Gergely Nagy <me@gergo.csillger.hu>