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

Asynchronous communication with Endoints via celery tasks #37

Merged
merged 5 commits into from
Jul 4, 2024

Conversation

jonas-rem
Copy link
Member

Based on #34

Communicating with Endpoints through a ReST API that is provided by leshan is slow. There can be several scenarios where an endpoints takes time to acknowledge (slow network, offline Endpoint, Endpoint waits for next eDRX Interval). The ReST call stays open for this time, until a timeout (up to several min) occurs.

It is essential to handle those ReST API calls in an asynchronous way so that the Django app can operate efficiently. API calls that are executed asynchronously via Celery still have access to Djangos database model and can update the result in the database after completion.

@jonas-rem jonas-rem self-assigned this Jun 8, 2024
@jonas-rem jonas-rem changed the title Implement Asynchronous Communication with Endoints via Celery Tasks Asynchronous Communication with Endoints via Celery Tasks Jun 8, 2024
@jonas-rem jonas-rem changed the title Asynchronous Communication with Endoints via Celery Tasks Asynchronous communication with Endoints via celery tasks Jun 8, 2024
@jonas-rem jonas-rem marked this pull request as ready for review June 10, 2024 13:24
@jonas-rem jonas-rem marked this pull request as draft June 10, 2024 13:25
@Kappuccino111 Kappuccino111 force-pushed the WIP/jonas-rem/leshan_registration_handler branch from d1ff295 to eddf65f Compare July 4, 2024 13:07
Base automatically changed from WIP/jonas-rem/leshan_registration_handler to main July 4, 2024 20:45
Integrate Celery task queue. Redis serves as the message broker for the
Celery task queue. Redis can run in a seperate container with
of-the-shelf available images.

Gevent is used an efficient alternative compared to multiple python
processes, where each process has to load it's own runtime resulting in
high memory requirement. Celery is used for functions that wait for ReST
API calls to Leshan, an IO-bound task. Currently, Celery starts
1 worker (1 CPU), however, this worker is sufficient to handle more than
100 simultaneous ReST API calls efficiently.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Signed-off-by: Jonas Remmert <jremmert@gmx.net>
The asynchronous function process_pending_operationss checks the
database for queued endpointOperations and sends them to the related
endpoint. The function is called e.g. during data insertion via the
Admin dashboard or during an registration update of an endpoing.

Signed-off-by: Jonas Remmert <jremmert@gmx.net>
Signed-off-by: Jonas Remmert <jremmert@gmx.net>
@jonas-rem jonas-rem marked this pull request as ready for review July 4, 2024 20:48
@jonas-rem jonas-rem merged commit 9828820 into main Jul 4, 2024
2 checks passed
@jonas-rem jonas-rem deleted the WIP/jonas-rem/async_comm branch July 4, 2024 20:49
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

Successfully merging this pull request may close these issues.

1 participant