-
Notifications
You must be signed in to change notification settings - Fork 710
cold run optimization #3132
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
Open
davidbuniat
wants to merge
15
commits into
main
Choose a base branch
from
tpch_optim_v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
cold run optimization #3132
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
89092fc
implementation of prefetcher
davidbuniat 62706af
minor fixes
davidbuniat ea99120
fixes
davidbuniat 131592f
minor update
davidbuniat 56b74f4
cpp updates
davidbuniat 5889034
added
davidbuniat 39df23d
startup scripts improved
davidbuniat d3081a8
Merge branch 'pg_server_start' into tpch_optim_v3
davidbuniat aef73f7
build system improvements
davidbuniat b176cd6
table data impl
davidbuniat 293323d
improvements
davidbuniat 1de810c
updates
davidbuniat 1f88eb8
further iterations
davidbuniat 3811d7d
improvements
davidbuniat 9c64d2b
cpp updates
davidbuniat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ | |||||||
| #include "table_storage.hpp" | ||||||||
| #include "utils.hpp" | ||||||||
|
|
||||||||
| #include <base/system_report.hpp> | ||||||||
|
|
||||||||
| #include <memory> | ||||||||
| #include <string> | ||||||||
| #include <vector> | ||||||||
|
|
@@ -74,6 +76,56 @@ std::unique_ptr<duckdb_connections> create_connections() | |||||||
| // Register the deeplake_scan table function for zero-copy access | ||||||||
| pg::register_deeplake_scan_function(*(conns->con_cpp)); | ||||||||
|
|
||||||||
| // Configure DuckDB memory management for large operations (e.g., JOINs at SF100+) | ||||||||
| // This prevents segfaults during memory-intensive operations by enabling disk spilling | ||||||||
| // | ||||||||
| // Memory configuration: | ||||||||
| // - If duckdb_memory_limit_mb > 0, use the explicit setting (in MB) | ||||||||
| // - Otherwise, auto-detect using 80% of system memory with 256MB minimum floor | ||||||||
| // - For containerized environments with cgroup limits, auto-detection may use host | ||||||||
| // memory instead of container limits; set pg_deeplake.duckdb_memory_limit_mb explicitly | ||||||||
| // | ||||||||
| // All memory values use MB units consistently throughout this codebase | ||||||||
| uint64_t mem_limit_mb = 0; | ||||||||
| if (pg::duckdb_memory_limit_mb > 0) { | ||||||||
| mem_limit_mb = static_cast<uint64_t>(pg::duckdb_memory_limit_mb); | ||||||||
| } else { | ||||||||
| // Auto-detect: use 80% of system memory | ||||||||
| uint64_t total_bytes = base::system_report::total_memory(); | ||||||||
| mem_limit_mb = static_cast<uint64_t>(total_bytes * 0.8 / (1024ULL * 1024ULL)); | ||||||||
| if (mem_limit_mb < 256) { | ||||||||
| mem_limit_mb = 256; // Minimum floor of 256MB | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Apply memory limit to DuckDB | ||||||||
| auto mem_result = conns->con_cpp->Query(fmt::format("SET memory_limit='{}MB'", mem_limit_mb)); | ||||||||
| if (!mem_result || mem_result->HasError()) { | ||||||||
| elog(WARNING, "Failed to set DuckDB memory_limit: %s", | ||||||||
| mem_result ? mem_result->GetError().c_str() : "null result"); | ||||||||
| } | ||||||||
|
|
||||||||
| // Configure temp directory for disk spilling (if specified) | ||||||||
| if (pg::duckdb_temp_directory != nullptr && std::strlen(pg::duckdb_temp_directory) > 0) { | ||||||||
| auto temp_result = conns->con_cpp->Query( | ||||||||
| fmt::format("SET temp_directory='{}'", pg::duckdb_temp_directory)); | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SQL injection vulnerability: User-controlled Fix: Use DuckDB's parameterized query API or properly escape the string:
Suggested change
|
||||||||
| if (!temp_result || temp_result->HasError()) { | ||||||||
| elog(WARNING, "Failed to set DuckDB temp_directory: %s", | ||||||||
| temp_result ? temp_result->GetError().c_str() : "null result"); | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| // Log DuckDB settings at INFO level for operational visibility | ||||||||
| auto verify_mem = conns->con_cpp->Query("SELECT current_setting('memory_limit')"); | ||||||||
| if (verify_mem && !verify_mem->HasError() && verify_mem->RowCount() > 0) { | ||||||||
| elog(INFO, "DuckDB memory_limit configured: %s", verify_mem->GetValue(0, 0).ToString().c_str()); | ||||||||
| } | ||||||||
|
|
||||||||
| auto verify_temp = conns->con_cpp->Query("SELECT current_setting('temp_directory')"); | ||||||||
| if (verify_temp && !verify_temp->HasError() && verify_temp->RowCount() > 0) { | ||||||||
| elog(INFO, "DuckDB temp_directory configured: %s", verify_temp->GetValue(0, 0).ToString().c_str()); | ||||||||
| } | ||||||||
|
|
||||||||
| // For now, we'll use C++ API for queries since table functions require it | ||||||||
| // The C API connection will be used later when we can restructure to avoid table functions | ||||||||
| // or when DuckDB provides a way to register table functions via C API | ||||||||
|
|
||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Missing implementation:
wait_for_first_batch()is declared but not implemented in any .cpp file. This will cause linker errors when the code is built.Fix: Implement this method in
async_prefetcher.cppor mark it as= deleteif it's not meant to be used yet.