Skip to content

Exact path configuration of Vert.x cache directory#5450

Merged
vietj merged 1 commit intoeclipse-vertx:masterfrom
geoand:remove-uuid
Feb 9, 2026
Merged

Exact path configuration of Vert.x cache directory#5450
vietj merged 1 commit intoeclipse-vertx:masterfrom
geoand:remove-uuid

Conversation

@geoand
Copy link
Contributor

@geoand geoand commented Jan 16, 2025

Motivation:

This is done because bootstrapping the plumbing
needed by the JDK to produce a UUID value
is expensive, it thus doesn't make sense to
pay this cost when the property isn't actually
needed

Explain here the context, and why you're making that change, what is the problem you're trying to solve.

We are making an effort in Quarkus to improve startup time even further by eliminating various bottlenecks across the board.
The first call to UUID.randomUUID() is definitely heavy (as shown in the following flamegraph) and if we can avoid it a startup code (as we have in the development branch of Quarkus), it would be nice.

uuid

P.S. Ideally we would like to have this in Vert.x 4 as well.

// the cacheDir will be suffixed a unique id to avoid eavesdropping from other processes/users
// also this ensures that if process A deletes cacheDir, it won't affect process B
String cacheDirName = fileCacheDir + "-" + UUID.randomUUID();
String cacheDirName = fileCacheDir + "-" + System.nanoTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoTime is not absolute - it's relative to the process. Meaning that another application starting can have it again, without any need to be simultaneous - is it what you expect?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nanoTime is not absolute - it's relative to the process

Correct. But we do think it can be problematic, I'm happy to use Random.getRandom() or System.currentTimeMillis()

Copy link
Contributor

@franz1981 franz1981 Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use Math.random() it get better - but is still not granted to be unique - because it still uses System::nanoTime and Random per se doesn't guarantee uniqueness across processes (try printing new Random(42).nextInt() running it twice with 2 diff processes...)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure we are not looking for that such strong of a guarantee here, but I'll let the maintainers be the judge of that

Copy link
Member

@tsegismont tsegismont Jan 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about an optimistic attempt? Something like (simplifying):

for(;;) {
  try {
    String cacheDirName = fileCacheDir + "-" + System.nanoTime();
    Files.createDirectories(cacheDirName);
    break;
  } catch(FileAlreadyExistException ignore) {
  }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, you could use a random instead of System.nanoTime, I think it would be faster

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@franz1981 is Random.nextLong() faster than System.nanoTime()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope - or better - usually nanoTime (if not on the cloud with unreliable time sources) uses a thing called rdts which is as cheap as reading a memory area


private String generateDeploymentID() {
return UUID.randomUUID().toString();
return Long.valueOf(System.nanoTime()).toString();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be globally unique when running in clustered mode with HA enabled

So perhaps something like:

    if (vertx.isClustered() && vertx.haManager()!=null) {
      return UUID.randomUUID().toString();
    }
    // Use a counter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's pretty common to deploy verticles concurrently. Even when Vert.x is not clustered, the returned value should be unique.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have updated it to use Random, is that what you meant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant incrementing an AtomicLong counter instead of using a random value (uniqueness is guaranteed and it shouldn't change the perf results you got)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, fixed

@vietj
Copy link
Member

vietj commented Jan 16, 2025

what seems to take time is the initialization of SecureRandom.getDfaultPrng due to loading providers, I think w ecould generate a faster UUID by using a given provider

@geoand
Copy link
Contributor Author

geoand commented Jan 16, 2025

what seems to take time is the initialization of SecureRandom.getDfaultPrng due to loading providers, I think w ecould generate a faster UUID by using a given provider

But those are not public APIs, no?

@vietj
Copy link
Member

vietj commented Jan 16, 2025

I think we should have a way to specify the exact cache dir (e.g. FileSystemOptions#exactFileCacheDir), when none is provided then it uses UUID. Quarkus would specify it in VertxOptions. This would easily be back-ported

@geoand
Copy link
Contributor Author

geoand commented Jan 16, 2025

Sure, that would make sense for us too

@geoand geoand force-pushed the remove-uuid branch 2 times, most recently from b28445c to 7c9fc8f Compare January 17, 2025 07:19
@geoand
Copy link
Contributor Author

geoand commented Jan 17, 2025

I have updated the PR per suggestions

@geoand
Copy link
Contributor Author

geoand commented Jan 21, 2025

Is there anything else you would like me to do for this one?

@tsegismont
Copy link
Member

I think we should have a way to specify the exact cache dir (e.g. FileSystemOptions#exactFileCacheDir), when none is provided then it uses UUID. Quarkus would specify it in VertxOptions. This would easily be back-ported

For usability, it seems to me adding a boolean to the options would be enough (it's what's computed in the end to determine if a UUID should be added to the path).

But it's a matter of taste so I'm fine with keeping an extra dir option if you choose so @vietj

@geoand
Copy link
Contributor Author

geoand commented Jan 30, 2025

Is there anything more you want me to do with this one?

@tsegismont tsegismont requested a review from vietj January 30, 2025 09:36
Copy link
Member

@tsegismont tsegismont left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @geoand

@tsegismont
Copy link
Member

@vietj PTAL

@geoand
Copy link
Contributor Author

geoand commented Jan 30, 2025

🙏🏽


public static final Logger log = LoggerFactory.getLogger(DefaultDeploymentManager.class);

private static final AtomicLong nextId = new AtomicLong();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the idea of cache dir is to avoid that, and keep the same behaviour we have, so please no.

Copy link
Contributor Author

@geoand geoand Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what do you propose? This was added as a response to #5450 (comment)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you confused two changes @vietj : the cache dir that used a random UUID, and the verticle id generator

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, can we have the verticle id generator in another PR then ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep distinct PR for the changelog

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Distinct PR or commit?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR updated

@geoand geoand force-pushed the remove-uuid branch 2 times, most recently from 8ba99cf to c749aaa Compare January 31, 2025 15:55
@geoand geoand changed the title Avoid UUID.randomUUID() in startup code Avoid UUID.randomUUID() in file system related startup code Jan 31, 2025
Copy link
Member

@vietj vietj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test with a real vertx instance and check those cases

  • a missing dir is created
  • an existing dir is reused
  • an error is thrown when a non dir file exist already

@geoand
Copy link
Contributor Author

geoand commented Feb 4, 2025

Sure, I'll do that when I'm back from JFokus

@geoand
Copy link
Contributor Author

geoand commented Feb 6, 2025

Aren't those cases already covered by the tests for FileResolver?

@vietj
Copy link
Member

vietj commented Feb 6, 2025

Aren't those cases already covered by the tests for FileResolver?

good question, I don't know :-)

@geoand geoand force-pushed the remove-uuid branch 2 times, most recently from c94173c to 5a95731 Compare January 23, 2026 06:43
@geoand geoand requested a review from vietj January 23, 2026 06:44
@geoand
Copy link
Contributor Author

geoand commented Feb 5, 2026

I would really appreciate some input on this

@geoand
Copy link
Contributor Author

geoand commented Feb 6, 2026

If this is approved, could it be backported to 4?

@vietj
Copy link
Member

vietj commented Feb 7, 2026

@geoand I would jsut like before to change the configuration option, instead of passing a different path exactFileCacheDir, I would prefer a boolean that configurations whether to use the existing path fully or as a directory.

@geoand
Copy link
Contributor Author

geoand commented Feb 7, 2026

@vietj Thanks. Can you elaborate a little more on what exactly you would like to see, because I don't fully underastand your proposal

@vietj
Copy link
Member

vietj commented Feb 9, 2026

@geoand instead of providing two paths, I prefer to keep the existing path value, but instead introduce a boolean that configures how it should be interpreted, either as a parent directory with a generated random child name or as an exact path directory to use, perhaps we could also improve that and when the path directory already exists, append a suffix "-2", "-3" to guarantee unicity whatsoever.

@geoand geoand force-pushed the remove-uuid branch 2 times, most recently from 76ff7ad to 2314102 Compare February 9, 2026 08:38
@geoand
Copy link
Contributor Author

geoand commented Feb 9, 2026

Thanks @vietj.

I believe the latest version of the PR addresses your concerns

@vietj
Copy link
Member

vietj commented Feb 9, 2026

lgtm @geoand

@geoand
Copy link
Contributor Author

geoand commented Feb 9, 2026

🙏🏽

@vietj
Copy link
Member

vietj commented Feb 9, 2026

@geoand I think we also need to rename this contribution to what it actually is : provide a way to use an exact path for a vertx instance instead of generating one based on random

@vietj
Copy link
Member

vietj commented Feb 9, 2026

@geoand there is a faiilure on windows

@geoand
Copy link
Contributor Author

geoand commented Feb 9, 2026

I will have a look

@geoand
Copy link
Contributor Author

geoand commented Feb 9, 2026

@geoand I think we also need to rename this contribution to what it actually is : provide a way to use an exact path for a vertx instance instead of generating one based on random

I updated the commit, but I can't update the PR title

@vietj vietj changed the title Avoid UUID.randomUUID() in file system related startup code Exact path configuration of Vert.x cache directory Feb 9, 2026
@vietj vietj merged commit 13cc58c into eclipse-vertx:master Feb 9, 2026
6 of 7 checks passed
@vietj
Copy link
Member

vietj commented Feb 9, 2026

@geoand can you backport this to 4.x and 5.0, we intent to do patch release this week of those branches and that would make it available

@geoand
Copy link
Contributor Author

geoand commented Feb 9, 2026

Sure thing, I'll do that tomorrow

@geoand
Copy link
Contributor Author

geoand commented Feb 10, 2026

#5958, #5959

@geoand geoand deleted the remove-uuid branch February 10, 2026 06:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants