Aspose Cells Docker

I’m currently experiencing an issue with the Aspose Cells Java Library while running it within a Ruby on Rails application. The environment setup includes Phusion Passenger, Nginx, and Docker. To integrate the Aspose Cells library, I’m using the Ruby Java Bridge (Rjb) gem.

Problem Description

Whenever I attempt to load a workbook from a template, Rjb freezes. I have monitored the memory consumption, and it seems that Rjb utilizes some memory which it never releases. Consequently, when I try to generate a PDF using Aspose Cells, the request to the endpoint never completes, indicating what seems like a memory leak.

Environment Details

  • Java Version:

    1 java 18.0.1.1 2022-04-22
    2 Java(TM) SE Runtime Environment (build 18.0.1.1+2-6)
    3 Java HotSpot(TM) 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)
    
  • Ruby on Rails Setup:

    • Ruby 2.6.8
    • Phusion Passenger ruby:2.6
    • Nginx
    • Docker
  • Gem:

    • Ruby Java Bridge (Rjb) (~> 1.7, >= 1.7.3)

Steps to Reproduce

  1. Load a workbook from a template using Aspose Cells.
  2. Attempt to generate a PDF from the loaded workbook.

Observations

  • Rjb freezes during the workbook loading process.
  • Memory consumption increases but memory is not freed.
  • The endpoint request to generate a PDF never completes.

Request

Any assistance in diagnosing and resolving this memory issue would be greatly appreciated. If further information or code snippets are required, I am happy to provide them.

Thank you for your support!

@juanb23
Would you like to provide your sample files and test code? We will check it soon.

1 Like

Below is an example of how we are loading the workbook in our code base. This is running inside of a docker containers with JDK 18 installed.

workbook = Rjb::import('com.aspose.cells.Workbook').new(AtEngine::Engine.root.join('spec', 'lib', 'test_objects', 'DerpaReportTemplate.xlsx').to_s)

When the code above runs code execution gets stuck here. There are no further logs or errors code execution just hangs there. The memory of the container increases but is never freed.

Our initializer configures the Apose cell jar as well as the lisence:

require 'rjb'
require 'logger'

logger = Logger.new(STDOUT)
logger.level = Logger::INFO

classpath = ::Dir.glob(AtEngine::Engine.root.join('jars', '**', '*.jar').to_s).join(':')
jvmargs = [
  '-Djava.awt.headless=true',
  '-Xmx2048m',
  '-Xms512m',
  '-XX:+UnlockExperimentalVMOptions',
  '-XX:+UseCGroupMemoryLimitForHeap'
]

begin
  Rjb::load(classpath, jvmargs)
  logger.info("RJB loaded successfully with classpath: #{classpath}")
rescue => e
  logger.error("Failed to load RJB: #{e.message}")
  raise
end

# Verify RJB is working by importing a basic Java class
begin
  string_class = Rjb::import('java.lang.String')
  logger.info("RJB is working correctly. Successfully imported java.lang.String")
rescue => e
  logger.error("RJB verification failed: #{e.message}")
  raise
end

begin
  aspose_license_file = ENV.fetch('ASPOSE_CELLS_JAVA_LICENSE_PATH') { '/path/to/Aspose.Cells.Java.lic' }
  
  if File.exist?(aspose_license_file)
    fstream = Rjb::import('java.io.FileInputStream').new(aspose_license_file)
    license = Rjb::import('com.aspose.cells.License').new()
    license.setLicense(fstream)
    logger.info("Aspose license loaded successfully from: #{aspose_license_file}")
  else
    logger.warn("Aspose license file not found: #{aspose_license_file}")
  end
rescue => e
  logger.error("Failed to load Aspose license: #{e.message}")
end

logger.info("RJB initialization completed")

@juanb23
Would you like to share your sample file named “DerpaReportTemplate.xlsx”? You can compress the file into zip format and upload it here. If the file is too large to upload, you can also upload it to a cloud drive and share the link here. We will check it soon.

I will verify that I can share the file with you and send it over if so. If not, we can send over a similar file that has the same issue.

However, the file most likely will not be the issue in my opinion. The file loads successfully when running the code on our host machines. Only when in docker do we run into these issues.

@juanb23
Thanks for your feedback. We will evaluate your issue further and get back to you soon.

@juanb23

Please share us a runnable project with docker file and detail steps to reproduce your issue.

Was this issue resolved.facing a similar issue

@ar123
Would you like to share us your sample excel file, a runnable project with docker file and detail steps to reproduce your issue. We will check it soon.

Closing the loop on this issue.

We were able to resolve this by loading RBJ and initializing JVM along side the code that was using RBJ to interface with Aspose Cells Java. Previously this was being done in our initializer. Below is the function we used along side the code using Rbj and Aspose cells to load and manipulate our excel workbook template, and then generate a PDF report.

  # Define a method to initialize Rjb
  def self.initialize_rjb
    unless Rjb.loaded?
      # Construct the classpath by globbing all JAR files in the specified directory
      classpath = Dir.glob(AtEngine::Engine.root.join('jars', '**', '*.jar').to_s).join(':')
      # Define JVM arguments
      jvmargs = [
        '-Xms512m',               # Set initial heap size to 512MB
        '-Xmx1G',                 # Set maximum heap size to 1GB
        '-Djava.awt.headless=true' # Run JVM in headless mode
      ]
      Rjb::load(classpath, jvmargs)
      aspose_license_file = ENV.fetch('ASPOSE_CELLS_JAVA_LICENSE_PATH') { '/path/to/Aspose.Cells.Java.lic' }
      fstream = Rjb::import('java.io.FileInputStream').new(aspose_license_file)
      license = Rjb::import('com.aspose.cells.License').new()
      license.setLicense(fstream)
      fstream.close()
    end
  end

@juanb23
Thank you for your feedback and provided solutions. The solution provides a good reference for other users who have encountered the same issue. Please feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.