EXTMEM Key Value Store?

1 post / 0 new
tekmage
tekmage's picture
Offline
Last seen: 3 hours 40 min ago
Joined: 2011-10-09 03:19
EXTMEM Key Value Store?

Hi All,

I've been thinking about how to maximize AmigaOS 4 on my X5000 and realized that EXTMEM is underutilized. We have a few apps that leverage EXTMEM; SketchBlock and Rave come to mind. I'm sure there are others, but each does it in its own way and is not coordinated.

While playing with AI, I started exploring EXTMEM and realized we could leverage mainstream key/value storage techniques in the EXTMEM space. Long time ago, the tech was called memcache. The power of this is huge; code can make easy get/set-type statements to store data blobs in the EXTMEM space at very healthy performance rates.

This is what valkey.library does. Provides a REDIS/ValKey-compatible API for the EXTMEM space found on A-Eon systems.

I wanted to post this here since it's a dev-focused forum; I'd love feedback and to gauge interest in this tool.

Here is what's implemented:
valkey.library/Append
valkey.library/DBSize
valkey.library/Del
valkey.library/Exists
valkey.library/Expire
valkey.library/ExpireAt
valkey.library/FlushDB
valkey.library/Get
valkey.library/GetAllKeys
valkey.library/GetExtMemStats
valkey.library/GetRange
valkey.library/GetStats
valkey.library/IncrBy
valkey.library/Persist
valkey.library/PurgeExpired
valkey.library/ReadVal
valkey.library/Set
valkey.library/SetNX
valkey.library/StrLen
valkey.library/TTL

Here is Set:
valkey.library/Set

NAME
Set -- Store a key-value pair in the database.

SYNOPSIS
bool Set(struct ValKeyIFace *Self, const char *key, uint32 key_len,
const void *val, uint32 val_len, uint32 ttl_secs);

FUNCTION
Stores the specified value associated with the given key string.
If val_len <= 48 bytes, the value is stored inline directly in the 32-bit
heap node with zero ExtMem allocation overhead. If val_len > 48 bytes,
the payload is allocated and stored directly in physical ExtMem DDR3 RAM.

INPUTS
Self - Pointer to ValKeyIFace interface.
key - Null-terminated or binary key string pointer.
key_len - Length of the key in bytes.
val - Pointer to the value data.
val_len - Length of the value data in bytes.
ttl_secs - Time-To-Live in seconds (0 = persistent / no expiration).

RESULT
true if successfully stored, false on memory allocation failure.

SEE ALSO
Get, SetNX, Del, Expire

Here is get:
valkey.library/Get

NAME
Get -- Retrieve the value associated with a key.

SYNOPSIS
bool Get(struct ValKeyIFace *Self, const char *key, uint32 key_len,
void **out_val, uint32 *out_val_len, bool *out_need_free);

FUNCTION
Looks up the active key and returns a pointer to its value data.
If the value is stored inline, out_val points directly into the
internal buffer and out_need_free is set to false.
If the value is stored in ExtMem, a temporary copy is allocated in 32-bit
heap, and out_need_free is set to true (the caller must call free(*out_val)).

INPUTS
Self - Pointer to ValKeyIFace interface.
key - Key string pointer.
key_len - Length of key in bytes.
out_val - Pointer to void* where value address is written.
out_val_len - Pointer to uint32 where value length is written.
out_need_free- Pointer to bool set to true if caller must free(*out_val).

RESULT
true if key was found and active, false if key does not exist or expired.

SEE ALSO
ReadVal, Set, Del

Here is a sample of the performance:
Size: 1 KB (5000 items) -> SET: 352783 ops/sec ( 344.52 MB/s) | ReadVal: 1519295 ops/sec (1483.69 MB/s)
Size: 64 KB (1000 items) -> SET: 33191 ops/sec (2074.41 MB/s) | ReadVal: 25541 ops/sec (1596.30 MB/s)
Size: 512 KB ( 200 items) -> SET: 2585 ops/sec (1292.64 MB/s) | ReadVal: 2021 ops/sec (1010.45 MB/s)
Size: 1 MB ( 50 items) -> SET: 1162 ops/sec (1161.58 MB/s) | ReadVal: 812 ops/sec ( 811.90 MB/s)
Size: 4 MB ( 10 items) -> SET: 146 ops/sec ( 585.40 MB/s) | ReadVal: 127 ops/sec ( 506.64 MB/s)

File attachments: 

AttachmentSize
Plain text icon valkey_library.txt11.79 KB