-
Notifications
You must be signed in to change notification settings - Fork 6
Implement parallel processing for log file reading and metrics aggregation #14
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
base: main
Are you sure you want to change the base?
Conversation
…ter confirming it's working properly, proceed to a multi-threaded approach. Add access log test data and implement unit tests for solution metrics - Created a new access log test file with extensive log entries for testing. - Implemented a Clojure test suite to validate the functionality of the solution. - Tests include calculations for total bytes, filtering by URL and referrer, and handling non-existent entries.
…dling Fetches Pokemon data asynchronously Implements asynchronous fetching of Pokémon types and details to improve performance. Adds error handling to gracefully manage potential API failures during data retrieval.
otus-16/src/otus_16/homework.clj
Outdated
| (def ^:const log-dir "./logs") | ||
|
|
||
| ;; Create a fixed thread pool for parallel processing | ||
| (def thread-pool (Executors/newFixedThreadPool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если ниже тут же используешь (.addShutdownHook задефайненный объект внутри замыкания (.shutdown thread-pool) и т.п. , прямо по месту, то лучше использовать defonce. Иначе при перезугрузке неймспейса в репл или при подключении в качестве зависимости в несколько других неймспейсов, весь код неймспейса может вычислиться дважды, что приведет к передефайну thread-pool, а старый может остаться висеть в системе, потому что на него висит его шатдаун хук.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо большое Андрей!
Поправил.
884bebc
otus-16/src/otus_16/homework.clj
Outdated
| (+ 14 (.. Runtime getRuntime availableProcessors)))) | ||
|
|
||
| ;; Add a shutdown hook to ensure the thread pool is properly shut down | ||
| (.addShutdownHook (Runtime/getRuntime) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Если операция идемпотентная (следующие вызовы после первого ничего не изменяют), то ок. Иначе - при перезагрузке модуля может повеситься 2 хука, 2 листенера и т.п. Поэтому лучше такой прямой мутирующий код в теле неймспейса не писать, а выносить в функции типа init, которые вызывать единожды в точке входа (мэйн или его аналоги)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо большое!
Исправил.
dd8fd61
This prevents re-initialization of the thread pool if the code is reloaded, ensuring resource consistency and avoiding potential issues with duplicate thread pools. It is particularly useful in development environments with hot-reloading.
Moved shutdown logic into a dedicated init-thread-pool function for clarity and reusability. This improves lifecycle control and avoids side effects at the namespace level. Note: This function should be called explicitly once at application startup (e.g. -main) to avoid multiple shutdown hooks in case of module reload.
Add asynchronous fetching of Pokémon types and details with error handling
Fetches Pokemon data asynchronously
Implements asynchronous fetching of Pokémon types and details to improve performance.
Adds error handling to gracefully manage potential API failures during data retrieval.