Skip to content

Commit

Permalink
add trace, perf mon, fix server mode, fix 3x fetch bug, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
xmilex-git committed Feb 12, 2025
1 parent f3db0a3 commit f32f7ba
Show file tree
Hide file tree
Showing 23 changed files with 256 additions and 39 deletions.
2 changes: 2 additions & 0 deletions cubrid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ set(PARALLEL_HEAP_SCAN_SOURCES
${PARALLEL_HEAP_SCAN_DIR}/phs_misc.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_result_queue.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_task.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_perf_monitor.cpp
)

set(PARALLEL_HEAP_SCAN_HEADERS
Expand All @@ -318,6 +319,7 @@ set(PARALLEL_HEAP_SCAN_HEADERS
${PARALLEL_HEAP_SCAN_DIR}/phs_misc.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_result_queue.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_task.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_perf_monitor.hpp
)

set(METHOD_SOURCES
Expand Down
2 changes: 2 additions & 0 deletions sa/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ set(PARALLEL_HEAP_SCAN_SOURCES
${PARALLEL_HEAP_SCAN_DIR}/phs_result_queue.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_task.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_checker.cpp
${PARALLEL_HEAP_SCAN_DIR}/phs_perf_monitor.cpp
)

set(PARALLEL_HEAP_SCAN_HEADERS
Expand All @@ -388,6 +389,7 @@ set(PARALLEL_HEAP_SCAN_HEADERS
${PARALLEL_HEAP_SCAN_DIR}/phs_result_queue.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_task.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_checker.hpp
${PARALLEL_HEAP_SCAN_DIR}/phs_perf_monitor.hpp
)

set(METHOD_SOURCES
Expand Down
2 changes: 1 addition & 1 deletion src/base/system_parameter.c
Original file line number Diff line number Diff line change
Expand Up @@ -2478,7 +2478,7 @@ static unsigned int prm_max_subquery_cache_size_flag = 0;
int PRM_PARALLEL_HEAP_SCAN_THREADS = 0;
static int prm_parallel_heap_scan_threads_default = 0;
static int prm_parallel_heap_scan_threads_lower = 0;
static int prm_parallel_heap_scan_threads_upper = 16;
static int prm_parallel_heap_scan_threads_upper = 64;
static unsigned int prm_parallel_heap_scan_threads_flag = 0;

typedef int (*DUP_PRM_FUNC) (void *, SYSPRM_DATATYPE, void *, SYSPRM_DATATYPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* phs_context.cpp - derived from cubthread::entry_manager
*/

#if defined (SERVER_MODE)
#if SERVER_MODE

#include "phs_context.hpp"
#include "error_context.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef _PARALLEL_HEAP_SCAN_CONTEXT_HPP_
#define _PARALLEL_HEAP_SCAN_CONTEXT_HPP_

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "scan_manager.h"
#include "phs_memory_mapper.hpp"
#include "phs_result_queue.hpp"
Expand Down
8 changes: 7 additions & 1 deletion src/query/parallel_query/parallel_heap_scan/phs_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
* phs_manager.cpp - manager for parallel heap scans executed within a single XASL
*/

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "phs_manager.hpp"
#include "phs_task.hpp"
#include "phs_perf_monitor.hpp"

#define PARALLEL_HEAP_SCAN_LOG 0

Expand Down Expand Up @@ -211,6 +212,11 @@ extern void
scan_close_parallel_heap_scan (THREAD_ENTRY *thread_p, SCAN_ID *scan_id)
{
HL_HEAPID orig_heap_id;
if (thread_is_on_trace (thread_p))
{
std::size_t parallelism = scan_id->s.phsid.manager->parallelism;
scan_id->s.phsid.perf_monitor = new parallel_heap_scan::perf_monitor (scan_id, parallelism);
}
orig_heap_id = db_change_private_heap (thread_p, 0);
delete scan_id->s.phsid.manager;
db_change_private_heap (thread_p, orig_heap_id);
Expand Down
6 changes: 3 additions & 3 deletions src/query/parallel_query/parallel_heap_scan/phs_manager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef _PARALLEL_HEAP_SCAN_MANAGER_HPP_
#define _PARALLEL_HEAP_SCAN_MANAGER_HPP_

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "dbtype.h"
#include "scan_manager.h"
#include "thread_manager.hpp"
Expand All @@ -42,6 +42,8 @@ namespace parallel_heap_scan

std::atomic<bool> m_is_start_once;
bool timeout_occurred;
std::vector<std::shared_ptr<memory_mapper>> m_memory_mappers;
std::size_t parallelism;

manager (THREAD_ENTRY *thread_p, SCAN_ID *scan_id, size_t pool_size, size_t task_max_count,
std::size_t core_count);
Expand All @@ -58,10 +60,8 @@ namespace parallel_heap_scan
private :
THREAD_ENTRY *m_thread_p;
SCAN_ID *m_scan_id;
std::size_t parallelism;
std::shared_ptr<context> m_context;
std::shared_ptr<result_queue> m_result_queue;
std::vector<std::shared_ptr<memory_mapper>> m_memory_mappers;
cubthread::entry_workpool *m_workpool;
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* heap scan-related information from the XASL structure.
*/

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "phs_memory_mapper.hpp"
#include "regu_var.hpp"
#include "query_executor.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#ifndef _PARALLEL_HEAP_SCAN_MEMORY_MAPPER_HPP_
#define _PARALLEL_HEAP_SCAN_MEMORY_MAPPER_HPP_

#if defined (SERVER_MODE)
#if SERVER_MODE

#include <unordered_map>
#include <atomic>
Expand Down Expand Up @@ -123,5 +123,5 @@ namespace parallel_heap_scan
REGU_VARIABLE *memory_mapper::copy_and_map<REGU_VARIABLE> (REGU_VARIABLE *regu_var);

}
#endif
#endif /* SERVER_MODE */
#endif /* _PARALLEL_HEAP_SCAN_MEMORY_MAPPER_HPP_ */
2 changes: 1 addition & 1 deletion src/query/parallel_query/parallel_heap_scan/phs_misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* phs_misc.cpp - miscellaneous functions for parallel heap scan
*/

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "phs_misc.hpp"
#include "memory_alloc.h"
#include "fetch.h"
Expand Down
4 changes: 2 additions & 2 deletions src/query/parallel_query/parallel_heap_scan/phs_misc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef _PARALLEL_HEAP_SCAN_MISC_HPP_
#define _PARALLEL_HEAP_SCAN_MISC_HPP_

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "regu_var.hpp"
#include "xasl_predicate.hpp"
#include "scan_manager.h"
Expand All @@ -39,5 +39,5 @@ namespace parallel_heap_scan
int arith_list_clear (THREAD_ENTRY *thread_p, ARITH_TYPE *list);
SCAN_CODE scan_next_heap_scan_1page_internal (THREAD_ENTRY *thread_p, SCAN_ID *scan_id, VPID *curr_vpid);
}
#endif
#endif /* SERVER_MODE */
#endif /* _PARALLEL_HEAP_SCAN_MISC_HPP_ */
68 changes: 68 additions & 0 deletions src/query/parallel_query/parallel_heap_scan/phs_perf_monitor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
*
* Copyright 2016 CUBRID Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
* phs_perf_monitor.cpp - performance monitor for parallel heap scan
*/
#if SERVER_MODE
#include "phs_perf_monitor.hpp"
#include "phs_memory_mapper.hpp"
#include "phs_manager.hpp"

// XXX: SHOULD BE THE LAST INCLUDE HEADER
#include "memory_wrapper.hpp"

namespace parallel_heap_scan
{
perf_monitor::perf_monitor (SCAN_ID *scan_id, std::size_t parallelism)
: m_parallelism (parallelism)
{
m_scan_stats.resize (parallelism);
for (std::size_t i = 0; i < parallelism; ++i)
{
m_scan_stats[i] = scan_id->s.phsid.manager->m_memory_mappers[i]->get_scan_id()->scan_stats;
}
}

perf_monitor::~perf_monitor()
{
}

void perf_monitor::print_text (FILE *fp, int indent, char *class_name)
{
for (std::size_t i = 0; i < m_parallelism; i++)
{
fprintf (fp, "\n");
fprintf (fp, "%*c", indent, ' ');
fprintf (fp, "(table: %s), ", class_name);
fprintf (fp, "(parallel heap");
fprintf (fp, " time: %d", TO_MSEC (m_scan_stats[i].elapsed_scan));
fprintf (fp, ", readrows: %llu, rows: %llu", (unsigned long long int) m_scan_stats[i].read_rows,
(unsigned long long int) m_scan_stats[i].qualified_rows);
fprintf (fp, ")");
}
}

void perf_monitor::print_json (FILE *fp)
{
}


}

#endif
46 changes: 46 additions & 0 deletions src/query/parallel_query/parallel_heap_scan/phs_perf_monitor.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
*
* Copyright 2016 CUBRID Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/

/*
* phs_result_queue.hpp - queue for temporarily storing heap scan results
*/

#ifndef _PARALLEL_HEAP_SCAN_PERF_MONITOR_HPP_
#define _PARALLEL_HEAP_SCAN_PERF_MONITOR_HPP_

#if SERVER_MODE
#include <vector>
#include <stdio.h>
#include "scan_manager.h"

namespace parallel_heap_scan
{
class perf_monitor
{
public:
perf_monitor (SCAN_ID *scan_id, std::size_t parallelism);
~perf_monitor();
void print_text (FILE *fp, int indent, char *class_name);
void print_json (FILE *fp);
private:
std::vector<SCAN_STATS> m_scan_stats;
std::size_t m_parallelism;
};
}
#endif
#endif /* _PARALLEL_HEAP_SCAN_PERF_MONITOR_HPP_ */
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
* phs_result_queue.cpp - queue for temporarily storing heap scan results
*/

#if defined (SERVER_MODE)
#if SERVER_MODE
#include "phs_result_queue.hpp"
#include "dbtype.h"
#include "regu_var.hpp"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#ifndef _PARALLEL_HEAP_SCAN_RESULT_QUEUE_HPP_
#define _PARALLEL_HEAP_SCAN_RESULT_QUEUE_HPP_

#if defined (SERVER_MODE)
#if SERVER_MODE
#include <vector>
#include "dbtype_def.h"
#include "scan_manager.h"
Expand Down Expand Up @@ -70,5 +70,5 @@ namespace parallel_heap_scan
};

}
#endif
#endif /* SERVER_MODE */
#endif /* _PARALLEL_HEAP_SCAN_RESULT_QUEUE_HPP_ */
Loading

0 comments on commit f32f7ba

Please sign in to comment.