-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
copr: migrate executor and aggr to be compatible with ChunkedVec
#8141
Conversation
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
ChunkRefNotChunkedVec
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
Signed-off-by: Alex Chi <iskyzh@gmail.com>
a763084
to
87680d1
Compare
|
@breeswish @TennyZhuang I've made the aggregation functions even safer by applying the following constraints. Developers should use impl<T> super::AggrFunctionStateUpdatePartial<T> for AggrFnStateFirst<T>
where
T: EvaluableRef<'static> + 'static,
VectorValue: VectorValueExt<T::EvaluableType>,
{
// ChunkedType has been implemented in AggrFunctionStateUpdatePartial<T1> for AggrFnStateFirst<T2>
impl_state_update_partial! { T }
}This macro will implement Developers should use generic lifetime in "safe" functions, so as to eliminate dangling pointer #[inline]
fn update_vector<'a, TT, CC>(
&mut self,
ctx: &mut EvalContext,
_phantom_data: Option<TT>,
physical_values: CC,
logical_rows: &[usize],
) -> Result<()>
where
TT: EvaluableRef<'a, EvaluableType = T::EvaluableType>,
CC: ChunkRef<'a, TT>,
{
if let Some(physical_index) = logical_rows.first() {
self.update(ctx, physical_values.get_option_ref(*physical_index))?;
}
Ok(())
}As we use a generic lifetime parameter, this code MUST be valid for all possible lifetime The only exception is in #[inline]
fn update_concrete<'a, TT>(&mut self, _ctx: &mut EvalContext, value: Option<TT>) -> Result<()>
where
TT: EvaluableRef<'a, EvaluableType = T::EvaluableType> + Ord,
{
let extreme_ref = self
.extremum_value
.as_ref()
.map(|x| TT::from_owned_value(unsafe { std::mem::transmute(x) }));
if value.is_some() && (self.extremum_value.is_none() || extreme_ref.cmp(&value) == E::ORD) {
self.extremum_value = value.map(|x| x.to_owned_value());
}
Ok(())
} |
|
@zhongzc PTAL~ Thanks! |
|
/bench +sysbench +tpcc +tpch |
Benchmark Report
@@ Benchmark Diff @@
================================================================================
tidb: 2b0b34b88e43ad20f4e5ab1a0b5daf7ae6ff6046
--- tikv: 3a4a0c98f9efc2b409add8cb6ac9e8886bb5730c
+++ tikv: fa4dcea87ac91a0c1bdc5f7c506911b6b4100776
pd: 9f1a55c0e36dba3ec35447d16d58dfd9d6becb90
================================================================================
oltp_update_index:
* QPS: 4872.17 ± 8.92% (std=311.74) delta: -1.12% (p=0.608)
* Latency p50: 27.91 ± 3.06% (std=0.60) delta: -2.47%
* Latency p99: 15.27 ± 0.00% (std=0.00) delta: 0.00%
oltp_insert:
* QPS: 5087.93 ± 10.50% (std=333.46) delta: 3.33% (p=0.778)
* Latency p50: 25.21 ± 10.89% (std=1.66) delta: -11.86%
* Latency p99: 12.75 ± 0.00% (std=0.00) delta: 0.00%
oltp_read_write:
* QPS: 9264.75 ± 0.68% (std=50.14) delta: 2.35% (p=0.726)
* Latency p50: 283.03 ± 3.62% (std=6.11) delta: -1.62%
* Latency p99: 168.63 ± 6.70% (std=8.08) delta: -18.96%
oltp_point_select:
* QPS: 113577.59 ± 0.55% (std=417.93) delta: -0.24% (p=0.498)
* Latency p50: 1.12 ± 0.44% (std=0.00) delta: 0.45%
* Latency p99: 4.18 ± 0.00% (std=0.00) delta: -1.65%
oltp_update_non_index:
* QPS: 6564.89 ± 9.87% (std=512.56) delta: 1.26% (p=0.845)
* Latency p50: 19.61 ± 9.54% (std=1.52) delta: -1.16%
* Latency p99: 12.98 ± 0.00% (std=0.00) delta: -0.00%
|
|
Hi @zhongzc , it seems that tpcc has failed and tpch has been running 14 hrs without a result. Shall we trigger benchmark again? |
|
/bench +tpcc +tpch |
Benchmark Report
@@ Benchmark Diff @@
================================================================================
tidb: 563f2c92d76ddd0b07672f6cd1952bba77f7b1df
--- tikv: 11cbf057ba8dec3a0833a9948b5ae9ec54d6113d
+++ tikv: fa4dcea87ac91a0c1bdc5f7c506911b6b4100776
pd: 16492b5e2e983f50622b2bbc614b646977abf07f
================================================================================
Measured tpmC (NewOrders): 246.88 ± 36.53% (std=57.64), delta: 9.76% (p=0.946) |
Codecov Report
@@ Coverage Diff @@
## master #8141 +/- ##
==========================================
- Coverage 84.77% 84.66% -0.12%
==========================================
Files 553 553
Lines 137630 137702 +72
==========================================
- Hits 116678 116580 -98
- Misses 20952 21122 +170
Continue to review full report at Codecov.
|
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.
LGTM
|
@zhongzc,Thanks for your review. |
|
/run-all-tests |
|
/merge |
|
/run-all-tests |
What problem does this PR solve?
Problem Summary
This PR refactors co-processor framework internally. Now all data flowing in aggregator and executor uses the new
BytesRef-like interface (orChunkRef). This laid solid foundation for migrating toChunkedVec.Overview
In RFC: Using chunk format in coprocessor framework, we proposed a
ChunkedVecstruct to support Chunk-based computing. We plan to:ChunkedVec.The detailed plan can be found at Full Chunk-based Computing PR Roadmap.
This PR follows #7979, #8019, #8070 . Now all internal stuff of copr uses
NotChunkedVecinstead ofVec<Option<T>>. AsNotChunkedVecexposes nearly the same interface as our proposedChunkedVec, we can directly replace this temporary struct with newChunkedVecin next PR.ChunkedVec.After migrating co-processor to have interface compatible with proposed
ChunkedVec, we can introduceChunkedVecinto TiKV. Then, we may further optimize performance by merging null parameters, etc.What is changed and how it works?
Proposal: RFC: Using chunk format in coprocessor framework
Related Issue: #7724
What's Changed:
The biggest change in this PR is the introduction of
NotChunkedVec.NotChunkedVechas nearly the same interface as the proposedChunkedVec. All data flowing in copr now uses this new struct instead ofVec<Option<T>>.tidb_query_codegen
rpn_fnnow generates code withNotChunkedVec.tidb_query_datatype
Jsonbefore is now refactored to takeJsonRef.map_option_ownedin collation, to support some aggregators.AsMySQLBoolonEvaluableReftypes. (e.g.&T,BytesRef)NotChunkedVec.ChunkRefnow implements a new function calledphantom_data, which returnsNoneof the correspondingEvaluableReftype. This is used to let compiler find dynamic dispatch function in aggregators. This will be explained later.UnsafeRefIntotrait, that is used to cast reference into'staticones.to_owned_valueandfrom_owned_valueforEvaluableRef.AsMutforVectorValue.NotChunkedVec
A vector type that internally stores
Option<T>, but only allows access toOption<&T>. It can be constructed fromVec<Option<T>>, or&[Option<T>].tidb_query_vec_aggr
impl ChunkRef. To make this process easier, the generic parameters are all set to'static.update_balahbalah_unsafe.update,update_concreate,update_vectorandupdate_repeatmacros for safely calling these traits.update_vector_unsafenow has a parameter with associative typeT::ChunkedType, the compiler cannot find corresponding function by dynamic dispatching whenAggrFunctionStateUpdatePartialis in a boxed type. In this way, we added aphantom_dataof typeOption<T>to this function, so as to make it compile. Users usingupdate_vector!macro don't need to supply this phantom parameter, as this has been done in macro.tidb_query_vec_executors
ChunkRefinternally.top_n_executor, where anas_slicecall is eliminated.TODO
tidb_query_vec_aggrinterface can be refactored without using unsafe primitives. This can be done later.top_n_executor, we still can't eliminate the overhead of clone.as_slicecalls from non-test code. This will be done later with a trait only available in tests.to_owned_valueinstead of.map(|x| x.as_ref())for code not modified in this PR.Check List
Tests