2

I have a Quarkus Application exposed as a REST API. I need to generate an Profile Guided Optimized Native Image for that application.

I looked into the Quarkus documentation but could not find much. Anyone has generated same ?

I have GraalVM Enterprise edition setup in my local machine.

For generating normal native image, this command is used :

./mvnw package -Dnative

Paras
  • 3,191
  • 6
  • 41
  • 77
  • You can add any flags GraalVM supports by configuring `quarkus.native.additional-build-args` – geoand Aug 21 '23 at 07:00
  • Error: Cannot load profile: default.iprof. Verify that the file exists and has appropriate access rights. com.oracle.svm.core.util.UserError$UserException: Cannot load profile: default.iprof. Verify that the file exists and has appropriate access rights. Any suggestion, where should I place the default.iprof file ? – Paras Aug 22 '23 at 07:22
  • Not really, I have never used it – geoand Aug 22 '23 at 08:59

1 Answers1

7

In general, generating an optimized executable includes the following steps:

  1. Build an instrumented app:

    native-image --pgo-instrument MyApp
    
  2. Run the instrumented executable and apply workloads to it to generate a profile file:

    ./myapp
    

This will generate a default.iprof file in the working directory. The quality of the workload (executing all relevant code paths) and giving the application enough time to collect profiles are essential for having complete profiling information and therefore the best performance. Note that the profile file won’t appear until after the application shutdown.

  1. Build an optimized executable. The profiles file with default name and location will be picked up automatically, alternatively you can pass it along:

     native-image --pgo=default.iprof MyApp
    

Now for a Quarkus application and building from Maven, what you can do is create corresponding profiles for those steps, for example:

    <profile>
   <id>instrumented</id>
    …
   <properties>
    …
    <quarkus.native.additional-build-args>--pgo-instrument</quarkus.native.additional-build-args>
   </properties>
   </profile>

and

    <profile>
   <id>optimized</id>
    …
   <properties>
    …
    <quarkus.native.additional-build-args>--pgo=${project.basedir}/default.iprof</quarkus.native.additional-build-args>
   </properties>
   </profile>

Alternatively the same should work from command line, for example:

./mvnw package -Dnative -Dquarkus.native.additional-build-args=--pgo=default.iprof
  • Hi Alina, thanks for your detailed explanation. I did managed to generate the default.iprof file, however when I am trying to regenerate the native image using the profile information, I am getting an exception stating "Error: Cannot load profile: default.iprof. Verify that the file exists and has appropriate access rights." Unfortunately, in the exception trace I am not able to see the path where GraalVM is trying to read file from. I tried to keep file at every possible place from project root to resources everywhere. Also, I am using a windows machine, does it has any impact ? – Paras Aug 23 '23 at 05:41
  • okay, I managed to solve the issue, it was due to path separator in Windows OS, somehow GraalVM was not able to resolve "\" so hardcoding it to "/" worked. – Paras Aug 23 '23 at 07:53