0

I'm building a jewellery e-commerce store, and a feature I'm building is incorporating current market gold prices into the final product price. I intend on updating the gold price every 3 days by making calls to an api using a scheduler, so the full process is automated and requires minimal interaction with the system.

My concern is this: will a scheduler, with one task executed every 72 hrs, slow down my server (using client-server model) and affect its performance?

The server side application is built using Django, Django REST framework, and PostgresSQL.

The scheduler I have in mind is Advanced Python Scheduler.

Rishi Surana
  • 65
  • 1
  • 6

1 Answers1

3

As far as I can see from the docs of "Advanced Python Scheduler", they do not provide a different process to run the scheduled tasks. That is left up to you to figure out.

From their docs, they are recommending a "BackgroundScheduler" which runs in a separate thread.

Now there are multiple issues which could arise:

  1. If you're running multiple Django instances (using gunicorn or uwsgi), APS scheduler will run in each of those processes. This is a non-trivial problem to solve unless APS has considered this (you will have to check the docs).
  2. BackgroundScheduler will run in a thread, but python is limited by the GIL. So if your background tasks are CPU intensive, your Django process will get slower at processing incoming requests.
  3. Regardless of thread or not, if your background job is CPU intensive + lasts a long time, it can affect your server performance.

APS seems like a much lower-level library, and my recommendation would be to use something simpler:

  1. Simply using system cronjobs to run every 3 days. Create a django management command, and use the cron to execute that.
  2. Use django supported libraries like celery, rq/rq-scheduler/django-rq, or django-background-tasks.

I think it would be wise to take a look at https://github.com/arteria/django-background-tasks as it is the simplest of all with the least amount of setup required. Once you get a bit familiar with this you can weigh the pros & cons on what is appropriate for your use case.

Once again, your server performance depends on what your background task is doing and how long does it lasts.

oxalorg
  • 2,768
  • 1
  • 16
  • 27
  • 1
    Again, your input is very much appreciated, thank you! It's not highly complex, it simply makes an API call at constant, set intervals and updates said value in the system - I have stored the gold price in the settings.py file. I do know that it will require a single thread to count down the time (or something like that?). I will take a look the django bg tasks to start with - will update once I find a solution! Thanks man, cheers! – Rishi Surana Jun 24 '20 at 15:37
  • Thanks, feel free to contact me via email (on my profile) if theres any issue. In the meanwhile I would appreciate if you could select this as an answer :) – oxalorg Jun 25 '20 at 07:07