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

Discussion: Optimisation API with intermittent tasks #56

Open
MarcelloTheArcane opened this issue Sep 9, 2024 · 4 comments
Open

Discussion: Optimisation API with intermittent tasks #56

MarcelloTheArcane opened this issue Sep 9, 2024 · 4 comments

Comments

@MarcelloTheArcane
Copy link

Hello,

Firstly, thank you for such a useful guide to using OR Tools! This has helped me considerably in setting up my optimisation program.

I'm not sure if this is an appropriate "issue", but I was wondering if you could help with the following query about an optimisation API.

I am setting up a model with three stages of optimisation, therefore the execution time is around 5 minutes. However, I'm only planning on executing the model once per day. I'm wondering about using Google Cloud to run my model since it looks like I'll only get charged for minutes used, rather than having an expensive server sitting idle for most of the time. If this is incorrect and there's a much better platform, please let me know!

Is it possible to run the FastAPI and Redis services on a small (cheap) server, and only run the optimisation API on demand? Would I need to set the optimisation API up separately in Cloud Run instead of being all in one container?

I'm new to Python, optimisation in general, OR Tools, and Google Cloud - sorry if this is a silly question!

@d-krupke
Copy link
Owner

d-krupke commented Sep 9, 2024

Google Cloud Run works excellent for this. A company I am consulting is using batch jobs which have some delay but you can get considerable resources at a pretty low price. Here is the general process:

  1. A simple API is waiting for the response, creating a GCS file with the input data, and creating the cloud job, which is just a CLI command with the optimization model to run and the file path(s).
  2. The optimization code has a CLI and is packed in a docker container. Google Cloud will start the container, run the command, and shut it down again. Important: This can take a few minutes and the jobs can only run a maximum of 60min, otherwise you need a more expensive service.
  3. The optimization code will write the result into GCS and call a webhook (optional, you can also just wait for the file).

You can probably also completely skip the part with the API and either trigger the command manually or do an automatic trigger once a specific file in GCS appears.

@MarcelloTheArcane
Copy link
Author

Thanks @d-krupke, that's very helpful. I like your suggestion of an automatic trigger, I reckon in my case I could set up a schedule to once per day.

@MarcelloTheArcane
Copy link
Author

I've set this up on Google Cloud, but have a couple of questions - would you be able to help out?

  1. I've set it up as a Cloud Job, but I seem to be limited to 8 vCPUs, and 32GB RAM maximum. Is there any way of increasing this?
  2. I have the Cloud Job on Github, with an automatic build. The build ends up failing, because my Cloud Job doesn't create a web server (it is executed ad hoc: it gets the data from Cloud Storage, runs the optimiser, and saves the result to Cloud Storage). Is this the wrong way to set it up? Should I turn it into a web server that does nothing, just to keep the Cloud Builder happy?

@d-krupke
Copy link
Owner

d-krupke commented Oct 2, 2024

Unfortunately, I am not an expert in Google Cloud. There should be an option for larger machines and you should not need a web server. A simple CLI command which you trigger should be enough. It kind of sounds odd how you set it up - the build should never fail as the build should only create the container that you trigger later on to run the CLI command.

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