Skip to content

ServiceOptions#getLibraryVersion() performance bottleneck/native memory leak. #2234

Description

@dargiri

Dear Google team,

During our internal performance testing of our application that is using google cloud java library (for accessing Google Datastore) we noticed abnormal native memory consumption (which was leading to java process being killed by Linux's OOM killer). It is caused by another bug in com.google.api.gax.core.PropertiesProvider (googleapis/gax-java#337). But it wouldn't happen if class com.google.cloud.ServiceOption had a little bit different implementation.

In method com.google.cloud.ServiceOptions#getLibraryVersion() properties are loaded each time from classpath. This method is used very intensively (as far as I understood during each request to REST service). Loading classpath resource is not efficient especially when application has large classpath with a lot of jars and resources.

Proposal is to add caching of method execution result. Even dumb implementation with whole method synchronization is more than 10 time faster.

Example:

public abstract class ServiceOptions<ServiceT extends Service<OptionsT>, OptionsT extends ServiceOptions<ServiceT, OptionsT>> implements Serializable {
    /**
    * Cached library version
    **/
    private String libraryVersion = null;

    //...

    public synchronized String getLibraryVersion() {
        if(this.libraryVersion != null) {
            return this.libraryVersion;
        }

        try {
            String version = this.getVersionProperty(this.getPackagePath());
            if(version == null) {
                version = this.getVersionProperty("com/google/cloud");
            }

            // Cache library version
            this.libraryVersion = version;

            return version;
        } catch (Exception var2) {
            return null;
        }
    }

     //...

}

BR,
Dionis

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions