0

So i have a very relatively simple java application spring 2.3.7 on java 8 that microservice simply calls DB to save update or retrive base64 image string thats all.

So i have deployed that in my server - xms 128 mb then pushed a load of 1000 users using k6 pushing load directly to that microservice.

All is similar to the same service method

public ApiSuccess uploadFiles(UploadFilesRequest request) throws GeneralException {

    log.info("In FileUploadService.uploadFiles");

    try {

        List<UserUploadFiles> files = request.getFiles();

        if (!CollectionUtils.isEmpty(files)) {
            for (UserUploadFiles file : files) {

                UploadedFileEntity fileEntity = smbUploadFileRepository.findByTransactionIdAndType(request.getTransactionId(), file.getType());

                if (!isAllowedBase64File(file.getData())) {
                    throw new GeneralException(
                            MessageCodes.COMMON_ERROR_MESSAGE.getMsgCode(),
                            Collections.singletonList(getInvalidFileTypeMessage()),
                            HttpStatus.BAD_REQUEST
                    );
                }

                if (null == fileEntity) {

                    fileEntity = new UploadedFileEntity();
                    fileEntity.setFile(file.getData());
                    fileEntity.setTransactionId(request.getTransactionId());
                    fileEntity.setType(file.getType());

                } else {
                    fileEntity.setFile(file.getData());
                }

                smbUploadFileRepository.save(fileEntity);
            }
        }

    }catch (GeneralException ge){
        throw ge;
    }
    catch (Exception ex) {
        log.error("Exception FileUploadService.uploadFiles : ", ex);
        throw new GeneralException(MessageCodes.FAILED_TO_GET_UPLOADED_FILES.getMsgCode(),
                                   Collections.singletonList(ex.getMessage()),
                                   HttpStatus.INTERNAL_SERVER_ERROR);
    }

    log.info("Exit FileUploadService.uploadFiles");
    return new ApiSuccess(HttpStatus.OK,
                          languageHelper.getMessagePropValue(MessageCodes.SUCESS_TO_SAVE_UPLOADED_FILES.getMsgCode(), null),
                          MessageCodes.SUCESS_TO_SAVE_UPLOADED_FILES.getMsgCode());
}

But it apprently takes 1GB to handle 200 concurrent users then once the load is 0 and i stop using the application and interacting with server itself

I checked visualVM heap usage this is what i see

enter image description here

after 3.15 there was 0 load then why did the objects accumulate and after sometime it becomes right angled triangle waves comes down goes every 5-10 minutes and yeah there is no schedular and stuff running.

One such instance is

enter image description here

There is no load here after 12.30

So is my application healthy and this is how java spring is supposed to behave or do i have any leak or retention as i checked but could not find anything.

3
  • You should read about Java Garbage Collector first if you didn't yet. Now to understand what exactly is happening to your application the best course of action is to do a memory dump and use a tool to analyze what is happening. Set your logs to debug/trace to see what Spring is doing in the background as well will also help Commented Oct 9 at 15:45
  • im little bit aware of GC, and yes i have taken heap dump and checked in eclipse MAT - i cannot see any leak suspect there only spring classes are taking max memory. and also is this the so called healthy behaviour of java application ? Commented Oct 10 at 7:07
  • The heap usage seems fine, even if there isn't anything running spring classes/proxies are still being used/created and the GC is doing its work just fine as the graph shows in the second image. Make sure you are properly closing the resources you are opening specially when working with files. For that check the classes you are using if they need explicitly closing or if they properly let GC handles it. Commented Oct 13 at 4:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.