Fix: remove I/O Blocking code on message processing parts #820
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR remove I/O blocking operations on parts used by message processing to bring back message parallelization
Related Clickup or Jira tickets : ALEPH-526
Self proofreading checklist
Changes
This pull request introduces significant changes to improve asynchronous handling across multiple modules, enhance efficiency, and ensure non-blocking operations. Key updates include replacing synchronous file and I/O operations with asynchronous alternatives, introducing semaphores to limit concurrent requests, and refactoring code to use shared
aiohttp.ClientSession
instances for HTTP requests.Asynchronous Enhancements:
src/aleph/handlers/content/aggregate.py
: Updated_prepend_to_aggregate
and_update_aggregate
to useasyncio.to_thread
for non-blocking execution ofmerge_aggregate_elements
. [1] [2]src/aleph/services/storage/fileystem_engine.py
: Replaced synchronous file operations with asynchronous equivalents usingaiofiles
, includingread
,write
,delete
, andexists
methods.HTTP Request Optimization:
src/aleph/services/p2p/http.py
: Refactoredapi_get_request
to use a sharedaiohttp.ClientSession
instead of maintaining separate session instances, improving resource management. Added semaphores to limit concurrent calls inget_peer_hash_content
andrequest_hash
. [1] [2] [3]src/aleph/services/p2p/jobs.py
: Introducedrequest_version
to handle peer version checks usingaiohttp.ClientSession
and asynchronous tasks. Refactoredtidy_http_peers_job
to utilizerequest_version
for better scalability. [1] [2]Code Cleanup:
src/aleph/handlers/content/post.py
: Removed debug print statements fromupdate_balances
for cleaner logging.These changes collectively enhance the system's scalability, responsiveness, and maintainability by leveraging asynchronous programming patterns effectively.
How to test
This PR doesn't add any breaking change, it's just running things in Non I/O blockign way