EXTMEM Key Value Store?

3 posts / 0 new
Last post
tekmage
tekmage's picture
Offline
Last seen: 18 hours 29 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
jabirulo
jabirulo's picture
Offline
Last seen: 1 day 10 hours ago
Joined: 2013-05-30 00:53
Re: EXTMEM Key Value Store?

I barelly understand what EXTMEM: to use above 2GB mem addresses or ... ???
So can you do the same performance test when using "normal" memory, so we can see if there is some improvmeent.
TiA

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonRX550/SSD240GB/DVDRW :-P

tekmage
tekmage's picture
Offline
Last seen: 18 hours 29 min ago
Joined: 2011-10-09 03:19
Re: EXTMEM Key Value Store?

Hi Jabirulo,

The issue is not competing with the 2GB of RAM available in the 32-bit space. It provides applications with access to the other 6 GB of RAM presented to the operating system on hardware that supports it. The audio editor RAVE is a great example of how EXTMEM can be used. In RAVE, when you execute a destructive change to a sample, RAVE will place the original data into the EXTMEM space. This allows the user to undo their changes very quickly without putting further pressure on addressable RAM or waiting for the far slower disk access.

The work I did was to adapt a common industry-standard Key/Value interface into a library for accessing the EXTMEM space. Using simple commands like "set" a "key" to a "value", like "set myimage1 , the application can then retrieve that image data QUICKLY with the "get" call.

The note about the hardware: EXTMEM is only available on certain platforms, like the X1000, X5000, and A1222+. It's not a universal solution, but when present, why not use all that extra memory space?

Cheers,
Bill

Log in or register to post comments