Skip to contentSkip to conversation

libuuid, extend cache in uuid_generate_time_generic()

PATCH Applied Michael Trapp 2 participants 2 messages Feb 24, 2022 – Mar 10, 2022 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libuuid, extend cache in uuid_generate_time_generic()

Improve throughput and reduce clock sequence increments for high load situation with time based version 1 uuids.
---
In a high load scenario, where an application continiously reads time based version 1 uuids from uuidd, we have noticed the following behaviour.

The application reads more uuids as there are available in the corresponding timeframe and each bulk request results in an increment of the clock sequence because of the 'step back' in time. Due to the 14bit size of the clock sequence this also results in overflows of the clock sequence.

As uuidd calls
uuid_generate_time_safe()
uuid_generate_time_generic()
the default value for the bulk request in the '#ifdef HAVE_TLS' section of uuid_generate_time_generic() is set to 1000.

Extending the 'cache' of uuid_generate_time_generic() by increasing the default of num to 1000000 doesn't solve the issue, but reduces the clock sequence increments by factor 1000 and it also improves the uuid throughput in our setup by factor 3-4.

It might be possible to implement a cache for
UUIDD_OP_BULK_TIME_UUID
UUIDD_OP_TIME_UUID
in the uuidd request handling, but it would not be as simple as this fix in uuid_generate_time_generic().

 src/gen_uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/gen_uuid.c +1 -1
index f2b30e1..12c2f09 100644
@@ -475,7 +475,7 @@ static int uuid_generate_time_generic(uuid_t out) {
 			num = 0;
 	}
 	if (num <= 0) {
-		num = 1000;
+		num = 1000000;
 		if (get_uuid_via_daemon(UUIDD_OP_BULK_TIME_UUID,
 					out, &num) == 0) {
 			last_time = time(NULL);
Signature · 1 line
2.28.0
maintainer Applied
#1 lore raw
Quoted 3 lines · Michael Trapp

In a high load scenario, where an application continiously reads time based version 1 uuids from uuidd, we have noticed the following behaviour.

It means that your application reads more than 1000 UUIDs per second in one thread :-) The "cache" has 1 second live-time.

Quoted 5 lines

The application reads more uuids as there are available in the corresponding timeframe and each bulk request results in an increment of the clock sequence because of the 'step back' in time. Due to the 14bit size of the clock sequence this also results in overflows of the clock sequence.

hmm ...

Quoted 11 lines

As uuidd calls
uuid_generate_time_safe()
uuid_generate_time_generic()
the default value for the bulk request in the '#ifdef HAVE_TLS' section of uuid_generate_time_generic() is set to 1000.

Extending the 'cache' of uuid_generate_time_generic() by increasing the default of num to 1000000 doesn't solve the issue, but reduces the clock sequence increments by factor 1000 and it also improves the uuid throughput in our setup by factor 3-4.

Well, uu.time_low is uint32_t, so there should be enough bytes to handle 1000000 UUIDs by the cache (and it also increments uu.time_mid and uu.time_hi_and_version).

If I read the code correctly than in theory the cache size could be UINT32_MAX.

Quoted 5 lines

It might be possible to implement a cache for
UUIDD_OP_BULK_TIME_UUID
UUIDD_OP_TIME_UUID
in the uuidd request handling, but it would not be as simple as this fix in uuid_generate_time_generic().

The question is, what is the bottleneck? From my point

rewind/flock/fscanf/rewind/fprintf/fflush/unlock

seems like a pretty expensive solution for the sequence file. Maybe for the next development we should think about something more elegant like a memory shared between uuidd instances. The question is also if uuidd has to share the file with the library because for extreme use-case like databases, it does not make sense.

Quoted 2 lines
 src/gen_uuid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Applied, thanks!

https://github.com/util-linux/util-linux/commit/0f8de4902fe3f3512ee5043c5277d002a488a804

Karel