low performance /info endpoint
The issue was found by the GC QA team while testing the /info endpoint for the entitlements service.
TC: request to https://community.gcp.gnrg-osdu.projects.epam.com/api/entitlements/v2/info under Apache JMeter with settings:
- Number of threads: 1000
- Loop count: Infinity
- Duration: 300 seconds
Result from VisualVM:
depends on the configuration of the pods.
Code with an issue:
public VersionInfo buildVersionInfo() throws IOException {
loadBuildInfoProperties();
loadGitProperties();
List<ConnectedOuterService> connectedOuterServices = loadConnectedOuterServices();
return VersionInfo.builder()
.groupId(buildInfoProperties.getProperty("build.group"))
.artifactId(buildInfoProperties.getProperty("build.artifact"))
.version(buildInfoProperties.getProperty("build.version"))
.buildTime(buildInfoProperties.getProperty("build.time"))
.branch(gitProperties.getProperty("git.branch"))
.commitId(gitProperties.getProperty("git.commit.id"))
.commitMessage(gitProperties.getProperty("git.commit.message.short"))
.connectedOuterServices(connectedOuterServices)
.build();
}
private void loadGitProperties() throws IOException {
InputStream gitStream =
this.getClass().getResourceAsStream(versionInfoProperties.getGitPropertiesPath());
if (gitStream != null) {
gitProperties.load(gitStream);
} else {
log.error(
"Git properties file not found by path: {}",
versionInfoProperties.getGitPropertiesPath());
}
}
private void loadGitProperties() throws IOException {
InputStream gitStream =
this.getClass().getResourceAsStream(versionInfoProperties.getGitPropertiesPath());
if (gitStream != null) {
gitProperties.load(gitStream);
} else {
log.error(
"Git properties file not found by path: {}",
versionInfoProperties.getGitPropertiesPath());
}
}
```
1. Strings should be constants.
2. InputStream should be closed.
3. Overwrite the logic in such a way as not to read the file every time on request and thereby reduce the IO operations.
Edited by Riabokon Stanislav(EPAM)[GCP]