...
It is proposed to create an end-to-end streaming solution, from Repository (database) to Rest interfacePersistence layer to Controller. A Proof of Concept will be constructed to document challenges and investigate performance characteristics.
...
Code Block | ||
---|---|---|
| ||
// In CPS core Stream<DataNode> queryDataNodesAsStream(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption) { return fragmentRepository.streamByAnchorAndCpsPath(getAnchor(dataspaceName, anchorName), cpsPath) .map(fragment -> fetchDescendants(fragment, fetchDescendantsOption)) .map(fragment -> toDataNodeconvertToDataNode(fragment)); } // In NCMP private YangModelCmHandle getAnyReadyCmHandleByModuleSetTag(final String moduleSetTag) { return cmHandleQueries.queryNcmpRegistryByCpsPath("/dmi-registry/cm-handles[@module-set-tag='" + moduleSetTag + "']", DIRECT_CHILDREN_ONLY) .map(YangDataConverter::convertCmHandleToYangModel) .filter(cmHandle -> cmHandle.getCompositeState().getCmHandleState() == CmHandleState.READY) .findFirst() .orElse(null); } |
...
Instead of returning Collections from Rest APIs, a Stream may be returned, reducing memory pressure on the server.
Current code looks like this:Rest APIs return ResponseEntity using Lists. This means the whole structure must be held in memory before returning response.
Code Block | ||
---|---|---|
| ||
@Override public ResponseEntity<List<String>> searchCmHandleIds(final CmHandleQueryParameters cmHandleQueryParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper.toCmHandleQueryServiceParameters(cmHandleQueryParameters); final Collection<String> cmHandleIds = networkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters); return ResponseEntity.ok(List.copyOf(cmHandleIds)); } |
It is proposed to stream out of the Rest API, something like this:return a Stream instead - Spring Boot supports this, and will allow returning very large results without incurring memory penalty.
Code Block | ||
---|---|---|
| ||
@Override public Stream<String> searchCmHandleIds(final CmHandleQueryParameters cmHandleQueryParameters) { final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = ncmpRestInputMapper.toCmHandleQueryServiceParameters(cmHandleQueryParameters); return networkCmProxyDataService.executeCmHandleIdSearchForInventory(cmHandleQueryServiceParameters); } |
Details of current memory consumption - conversion of collections
The read APIs in CPS Core (cps-service and cps-ri) return Collection<DataNode>:
...