Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Managing memory for multiple LP instances #45

Open
zuzhaoye opened this issue Oct 14, 2024 · 1 comment
Open

Managing memory for multiple LP instances #45

zuzhaoye opened this issue Oct 14, 2024 · 1 comment

Comments

@zuzhaoye
Copy link

zuzhaoye commented Oct 14, 2024

Hi GLPK team,

First, thanks for providing such a powerful library! I’m currently using glpk.js in a project and looking for some advice with a memory issue.

1. Context:

  • Using GLPK.js in a web application (React)
  • Each run involves solving 25 LP instances
  • Each instance has approximately 200 decision variables and 200 constraints
  • The application runs perfectly for the first 4 runs
  • Everytime, on the 5th run, I encounter the following error:

ERROR Uncaught RangeError: WebAssembly.Instance(): Out of memory: Cannot allocate Wasm memory for new instance at handleError (http://localhost:3000/static/js/bundle.js:394110:58) at http://localhost:3000/static/js/bundle.js:394129:7

2. Current Approach: (not working)
I tried to assign the problem instance to null after solving, but it did not work. Here is how my code looks like in general:

import GLPK from 'glpk.js';

export const runOP = async ({ inputs }) => {

  // Extract input values
 (details skipped)

  // Load GLPK
  let glpk = await GLPK();

  // Prepare the model
  let lp = {
    name: 'MyOP',
    objective: {
      direction: glpk.GLP_MIN,
      name: 'cost',
      vars: []
    },
    subjectTo: [],
    vars: {}
  };

  // Add variables
  (details skipped)

  // Solve the problem
  try {
    const result = await glpk.solve(lp);
    // Extract results
    (details skipped)

    return {
      status: status,
      optimalCost: optimalCost,
    };
  } catch (error) {
    console.error('Error solving LP:', error);
    return {
      status: 'Error',
      optimalCost: null,
    };
  } finally {
    // Try to clean up, but did not work
    lp = null;
    glpk = null;
  }
};

3. Question:
Do you have any suggestions for managing memory in this scenario to avoid the out-of-memory error?

4. Additional Information:
Browser: Chrome, 128.0.6613.138
GLPK.js version: 4.0.2
Node.js version: v20.15.1

@zuzhaoye zuzhaoye changed the title Advice seeking: Managing memory for multiple large LP instances Managing memory for multiple LP instances Oct 16, 2024
@zuzhaoye zuzhaoye closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2024
@zuzhaoye zuzhaoye reopened this Oct 17, 2024
@jvail
Copy link
Owner

jvail commented Oct 30, 2024

Hi @zuzhaoye, I am afraid there is no team - just me and my ~10 tiny fingers. If you could put together a working example with a sufficiently large LP then I can give it a try. Maye take an example from here https://github.com/Ivordir/YALPS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants