Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
eabb65b
WIP nothing worked, just recording the progress
HeartSaVioR Sep 4, 2018
c3076d2
WIP not working yet... lots of implementations needed
HeartSaVioR Sep 6, 2018
9d59c7a
WIP Finished implementing UpdatingSessionIterator
HeartSaVioR Sep 6, 2018
b38f2b9
WIP add verification on precondition "rows in iterator are sorted by …
HeartSaVioR Sep 7, 2018
668c1f5
Rename SymmetricHashJoinStateManager to MultiValuesStateManager
HeartSaVioR Sep 8, 2018
9f63a3c
Move package of UpdatingSessionIterator
HeartSaVioR Sep 8, 2018
5d17ac8
WIP add MergingSortWithMultiValuesStateIterator, now integrating with…
HeartSaVioR Sep 10, 2018
ec33265
WIP the first version of working one! Still have lots of TODOs and FI…
HeartSaVioR Sep 13, 2018
8b210d5
Add more explanations
HeartSaVioR Sep 13, 2018
7255bca
Silly bugfix & block session window for batch query as of now
HeartSaVioR Sep 13, 2018
7b57fe5
More works: majorly split out updating session to individual physical…
HeartSaVioR Sep 13, 2018
969859b
Fix a silly bug and also add check for session window against batch q…
HeartSaVioR Sep 13, 2018
f5ecbdd
WIP Fixed eviction on update mode
HeartSaVioR Sep 13, 2018
b180772
WIP found root reason of broken UT... fixed it
HeartSaVioR Sep 13, 2018
0a2d731
WIP remove printing "explain" on UTs
HeartSaVioR Sep 13, 2018
6ee901e
WIP address session to batch query (+ python) as well... not having t…
HeartSaVioR Sep 13, 2018
395606b
WIP add more test on session batch query
HeartSaVioR Sep 13, 2018
f6bb34d
WIP add UT for sessions with keys overlapped
HeartSaVioR Sep 14, 2018
22fffd2
WIP refactor a bit
HeartSaVioR Sep 14, 2018
847f69e
WIP add more FIXMEs for javadoc, and remove invalid FIXMEs
HeartSaVioR Sep 14, 2018
104df13
WIP Repackage & remove unnecessary field
HeartSaVioR Sep 17, 2018
8108fc5
WIP addressed UPDATE mode, but doesn't look like performant
HeartSaVioR Sep 17, 2018
35c8fef
WIP remove FIXME since it is not relevant
HeartSaVioR Sep 17, 2018
6b1d1e0
WIP update numOutputRows for Append mode
HeartSaVioR Sep 17, 2018
86b3060
WIP apply aggregations when merging sessions
HeartSaVioR Sep 18, 2018
f7c2deb
WIP simplify the code a bit
HeartSaVioR Sep 18, 2018
a81616b
WIP address batch distinct query for sessionization
HeartSaVioR Sep 18, 2018
013785d
WIP remove debug statements for test code
HeartSaVioR Sep 18, 2018
37fffef
WIP remove debug informations
HeartSaVioR Sep 18, 2018
df95e72
WIP port Sessionization example to UT of session window
HeartSaVioR Sep 18, 2018
16d6421
WIP remove unnecessary thing
HeartSaVioR Sep 18, 2018
dc43300
WIP fix all the issues with sessionization example UTs
HeartSaVioR Sep 19, 2018
3637f60
WIP apply merging session in each partition before shuffling
HeartSaVioR Sep 19, 2018
0d53831
Fix scala checkstyle
HeartSaVioR Sep 20, 2018
a781400
Fix python style check
HeartSaVioR Sep 20, 2018
918dad2
WIP add complete mode, fix tricky bugs, apply ExternalAppendOnlyUnsaf…
HeartSaVioR Oct 8, 2018
fd6377b
WIP add "session" function to exclude list for description
HeartSaVioR Oct 8, 2018
e029e12
WIP rename function & column name "session" to "session_window"
HeartSaVioR Oct 10, 2018
a2fc652
WIP reducing unnecessary codegen which seriously harmed performance
HeartSaVioR Oct 15, 2018
2dc413b
WIP reduce codegen once again for MergingSessionsIterator
HeartSaVioR Oct 15, 2018
4dd0e89
WIP optimize a bit more on codegen...
HeartSaVioR Oct 15, 2018
cf52044
WIP make the feature "merge session in local partition" optional
HeartSaVioR Oct 15, 2018
5c74609
WIP add "session_window" to exclude list
HeartSaVioR Oct 17, 2018
fb6c59f
WIP Enable versioning of session window state format
HeartSaVioR Oct 18, 2018
dd29af2
WIP some correction in comment
HeartSaVioR Oct 19, 2018
1f6e496
WIP cover all the cases for session window in UTs
HeartSaVioR Oct 20, 2018
0673b6e
WIP Add Linked List data structure for storing session windows
HeartSaVioR Oct 23, 2018
4698f6d
WIP add SessionWindowLinkedListStateStoreRDD
HeartSaVioR Oct 23, 2018
5c67f72
WIP add more functionalities to SessionWindowLinkedListState
HeartSaVioR Oct 24, 2018
7bb0060
WIP it works but a bit suboptimal
HeartSaVioR Oct 25, 2018
35c9712
WIP optimized!
HeartSaVioR Oct 25, 2018
ede078a
WIP remove requirement on sort, add UT to test linked list state with…
HeartSaVioR Oct 27, 2018
f8e8ff6
WIP add code to print out information when task crashes with dangling…
HeartSaVioR Oct 27, 2018
b05abc7
WIP fixed the issue with benchmark run
HeartSaVioR Oct 29, 2018
17570f2
WIP optimize a bit on storing new sessions
HeartSaVioR Oct 30, 2018
958de31
WIP Fixed critical bug which tasks don't respect preference on state …
HeartSaVioR Oct 31, 2018
ee67bca
WIP Fix critical perf. issue: remove codegen on generating session ro…
HeartSaVioR Nov 1, 2018
8a0331e
WIP Rolling back unnecessary changes
HeartSaVioR Nov 2, 2018
b6ccecd
WIP Apply removing codegen to UpdatingSessionIterator as well
HeartSaVioR Nov 2, 2018
75c7611
WIP remove state version for now: it will be reintroduced when actual…
HeartSaVioR Nov 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WIP Fix critical perf. issue: remove codegen on generating session ro…
…w for group key

Also modify CodeGenerator to print out debug information when code generation takes too long
  • Loading branch information
HeartSaVioR committed Nov 1, 2018
commit ee67bcaf6fa2d1ab17e755cb7d5edd5dd10115bc
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,10 @@ object CodeGenerator extends Logging {
// bytecode instruction
final val MUTABLESTATEARRAY_SIZE_LIMIT = 32768

// This is the threshold to print out debug information when code generation takes more
// than this value.
final val SLOW_CODEGEN_MILLIS_THRESHOLD = 100

/**
* Compile the Java source code into a Java class, using Janino.
*
Expand Down Expand Up @@ -1375,6 +1379,27 @@ object CodeGenerator extends Logging {
CodegenMetrics.METRIC_SOURCE_CODE_SIZE.update(code.body.length)
CodegenMetrics.METRIC_COMPILATION_TIME.update(timeMs.toLong)
logInfo(s"Code generated in $timeMs ms")

if (timeMs > SLOW_CODEGEN_MILLIS_THRESHOLD) {
logWarning(s"Code generation took more than $SLOW_CODEGEN_MILLIS_THRESHOLD ms." +
"Please set logger level to DEBUG to see further debug information.")

logDebug(s"Printing out debug information - body: ${code.body}... / " +
s"comment: ${code.comment}")

def getRelevantStackTraceForDebug(): Array[StackTraceElement] = {
Thread.currentThread().getStackTrace.drop(1)
.filterNot { p =>
p.getClassName.startsWith("com.google.common") ||
p.getClassName.startsWith("org.apache.spark.sql.catalyst") ||
p.getClassName.startsWith("org.apache.spark.rdd")
}
}

logDebug(s"Stack trace - " +
s"${getRelevantStackTraceForDebug().take(30).map(_.toString).mkString("\n")}")
}

result
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package org.apache.spark.sql.execution.aggregate

import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.{Attribute, BindReferences, CreateNamedStruct, Expression, GenericInternalRow, JoinedRow, Literal, MutableProjection, NamedExpression, PreciseTimestampConversion, UnsafeProjection, UnsafeRow}
import org.apache.spark.sql.catalyst.expressions.{Attribute, BindReferences, CreateNamedStruct, Expression, GenericInternalRow, JoinedRow, Literal, MutableProjection, NamedExpression, PreciseTimestampConversion, SpecificInternalRow, UnsafeProjection, UnsafeRow}
import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
import org.apache.spark.sql.catalyst.expressions.codegen.GenerateUnsafeProjection
import org.apache.spark.sql.execution.metric.SQLMetric
Expand Down Expand Up @@ -82,16 +82,12 @@ class MergingSessionsIterator(
// The partition key of the current partition.
private[this] var currentGroupingKey: UnsafeRow = _

private[this] var currentSessionStart: Long = Long.MaxValue

private[this] var currentSessionEnd: Long = Long.MinValue
private[this] var currentSession: UnsafeRow = _

// The partition key of next partition.
private[this] var nextGroupingKey: UnsafeRow = _

private[this] var nextGroupingSessionStart: Long = Long.MaxValue

private[this] var nextGroupingSessionEnd: Long = Long.MinValue
private[this] var nextGroupingSession: UnsafeRow = _

// The first row of next partition.
private[this] var firstRowInNextGroup: InternalRow = _
Expand All @@ -116,9 +112,7 @@ class MergingSessionsIterator(
val inputRow = inputIterator.next()
nextGroupingKey = groupingWithoutSessionProjection(inputRow).copy()
val session = sessionProjection(inputRow)
val sessionRow = session.getStruct(0, 2)
nextGroupingSessionStart = sessionRow.getLong(0)
nextGroupingSessionEnd = sessionRow.getLong(1)
nextGroupingSession = session.getStruct(0, 2).copy()
firstRowInNextGroup = inputRow.copy()
sortedInputHasNewGroup = true
} else {
Expand All @@ -132,8 +126,7 @@ class MergingSessionsIterator(
/** Processes rows in the current group. It will stop when it find a new group. */
protected def processCurrentSortedGroup(): Unit = {
currentGroupingKey = nextGroupingKey
currentSessionStart = nextGroupingSessionStart
currentSessionEnd = nextGroupingSessionEnd
currentSession = nextGroupingSession

// Now, we will start to find all rows belonging to this group.
// We create a variable to track if we see the next group.
Expand All @@ -149,27 +142,27 @@ class MergingSessionsIterator(
val groupingKey = groupingWithoutSessionProjection(currentRow)

val session = sessionProjection(currentRow)
val sessionRow = session.getStruct(0, 2)
val sessionStart = sessionRow.getLong(0)
val sessionEnd = sessionRow.getLong(1)
val sessionStruct = session.getStruct(0, 2)
val sessionStart = getSessionStart(sessionStruct)
val sessionEnd = getSessionEnd(sessionStruct)

// Check if the current row belongs the current input row.
if (currentGroupingKey == groupingKey) {
if (sessionStart < currentSessionStart) {
if (sessionStart < getSessionStart(currentSession)) {
throw new IllegalArgumentException("Input iterator is not sorted based on session!")
} else if (sessionStart <= currentSessionEnd) {
} else if (sessionStart <= getSessionEnd(currentSession)) {
// expanding session length if needed
expandEndOfCurrentSession(sessionEnd)
processRow(sortBasedAggregationBuffer, currentRow)
} else {
// We find a new group.
findNextPartition = true
startNewSession(currentRow, groupingKey, sessionStart, sessionEnd)
startNewSession(currentRow, groupingKey, sessionStruct)
}
} else {
// We find a new group.
findNextPartition = true
startNewSession(currentRow, groupingKey, sessionStart, sessionEnd)
startNewSession(currentRow, groupingKey, sessionStruct)
}
}

Expand All @@ -180,17 +173,28 @@ class MergingSessionsIterator(
}
}

private def startNewSession(currentRow: InternalRow, groupingKey: UnsafeRow, sessionStart: Long,
sessionEnd: Long): Unit = {
private def startNewSession(currentRow: InternalRow, groupingKey: UnsafeRow,
sessionStruct: UnsafeRow): Unit = {
nextGroupingKey = groupingKey.copy()
nextGroupingSessionStart = sessionStart
nextGroupingSessionEnd = sessionEnd
nextGroupingSession = sessionStruct.copy()
firstRowInNextGroup = currentRow.copy()
}

private def getSessionStart(sessionStruct: UnsafeRow): Long = {
sessionStruct.getLong(0)
}

private def getSessionEnd(sessionStruct: UnsafeRow): Long = {
sessionStruct.getLong(1)
}

def updateSessionEnd(sessionStruct: UnsafeRow, sessionEnd: Long): Unit = {
sessionStruct.setLong(1, sessionEnd)
}

private def expandEndOfCurrentSession(sessionEnd: Long): Unit = {
if (sessionEnd > currentSessionEnd) {
currentSessionEnd = sessionEnd
if (sessionEnd > getSessionEnd(currentSession)) {
updateSessionEnd(currentSession, sessionEnd)
}
}

Expand Down Expand Up @@ -225,17 +229,9 @@ class MergingSessionsIterator(
groupingWithoutSessionAttributes :+ sessionExpression.toAttribute)

private def generateGroupingKey(): UnsafeRow = {
val sessionStruct = CreateNamedStruct(
Literal("start") ::
PreciseTimestampConversion(
Literal(currentSessionStart, LongType), LongType, TimestampType) ::
Literal("end") ::
PreciseTimestampConversion(
Literal(currentSessionEnd, LongType), LongType, TimestampType) ::
Nil)

val joined = join(currentGroupingKey,
UnsafeProjection.create(sessionStruct).apply(InternalRow.empty))
val newRow = new SpecificInternalRow(Seq(sessionExpression.toAttribute).toStructType)
newRow.update(0, currentSession)
val joined = join(currentGroupingKey, newRow)

groupingKeyProj(joined)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package org.apache.spark.sql.execution.streaming.state
import java.util.Locale

import org.apache.hadoop.conf.Configuration

import org.apache.spark.TaskContext
import org.apache.spark.internal.Logging
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference, Expression, Literal, SpecificInternalRow, UnsafeProjection, UnsafeRow}
Expand Down