Skip to content

Commit f1f675c

Browse files
author
Sumedh Wale
committed
skip dynamic cpusPerTask setting with smart connector
also fix few dunit test failures in ColumnBatchAndExternalTableDUnitTest
1 parent 29f2705 commit f1f675c

199 files changed

Lines changed: 93 additions & 48 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cluster/src/dunit/scala/io/snappydata/cluster/SplitSnappyClusterDUnitTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,7 @@ object SplitSnappyClusterDUnitTest
931931
.set("snappydata.connection", connectionURL)
932932
.set("snapptdata.sql.planCaching", random.nextBoolean().toString)
933933
.set(Property.TestDisableCodeGenFlag.name, "false")
934-
logInfo("Spark conf:" + conf.getAll.toString)
934+
logInfo("Spark conf: " + conf.getAll.mkString(", "))
935935

936936
val sc = SparkContext.getOrCreate(conf)
937937
// sc.setLogLevel("DEBUG")

cluster/src/dunit/scala/org/apache/spark/sql/ColumnBatchAndExternalTableDUnitTest.scala

Lines changed: 50 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,22 @@ package org.apache.spark.sql
1818

1919

2020
import com.pivotal.gemfirexd.internal.engine.Misc
21-
import io.snappydata.Property
2221
import io.snappydata.cluster.ClusterManagerTestBase
2322
import io.snappydata.test.dunit.{AvailablePortHelper, SerializableCallable}
2423
import io.snappydata.util.TestUtils
24+
import io.snappydata.{Property, SnappyFunSuite}
2525
import org.scalatest.Assertions
2626

2727
import org.apache.spark.internal.Logging
2828
import org.apache.spark.scheduler.{SparkListener, SparkListenerTaskEnd, SparkListenerTaskStart}
29+
import org.apache.spark.sql.execution.ui.SQLExecutionUIData
2930

3031
case class TestRecord(col1: Int, col2: Int, col3: Int)
3132

3233
class ColumnBatchAndExternalTableDUnitTest(s: String) extends ClusterManagerTestBase(s)
3334
with Assertions with Logging with SparkSupport {
3435

35-
private def activeExecutionIds(session: SparkSession): Set[Long] = {
36+
private def sqlExecutionIds(session: SparkSession): Set[Long] = {
3637
session.sharedState.statusStore.executionsList().map(_.executionId).toSet
3738
}
3839

@@ -53,144 +54,148 @@ class ColumnBatchAndExternalTableDUnitTest(s: String) extends ClusterManagerTest
5354

5455
import session.implicits._
5556

56-
val ds = session.createDataset(sc.range(1, 101).map(i =>
57+
val ds = session.createDataset(sc.range(1, 1001).map(i =>
5758
AirlineData(2015, 2, 15, 1002, i.toInt, "AA" + i)))
5859
ds.write.insertInto("airline")
5960

6061
// ***Check for the case when all the column batches are scanned ****
61-
var previousExecutionIds = activeExecutionIds(session)
62+
var previousExecutionIds = sqlExecutionIds(session)
6263

6364
val df_allColumnBatchesScan = session.sql(
6465
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
65-
"from AIRLINE where ArrDelay < 101 " +
66+
"from AIRLINE where ArrDelay < 1001 " +
6667
"group by UniqueCarrier order by arrivalDelay")
6768

68-
df_allColumnBatchesScan.count()
69+
df_allColumnBatchesScan.collect()
6970

70-
var executionIds = activeExecutionIds(session).diff(previousExecutionIds)
71+
var executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
7172

7273
var executionId = executionIds.head
7374

74-
val (scanned1, skipped1) =
75-
findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
75+
val (scanned1, skipped1) = findColumnBatchStats(session, executionId)
7676
assert(skipped1 == 0, "All Column batches should have been scanned")
7777
assert(scanned1 > 0, "All Column batches should have been scanned")
7878

7979
// ***Check for the case when all the column batches are skipped****
80-
previousExecutionIds = activeExecutionIds(session)
80+
previousExecutionIds = sqlExecutionIds(session)
8181

8282
val df_noColumnBatchesScan = session.sql(
8383
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
84-
"from AIRLINE where ArrDelay > 101 " +
84+
"from AIRLINE where ArrDelay > 1001 " +
8585
"group by UniqueCarrier order by arrivalDelay")
8686

87-
df_noColumnBatchesScan.count()
87+
df_noColumnBatchesScan.collect()
8888

89-
executionIds = activeExecutionIds(session).diff(previousExecutionIds)
89+
executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
9090

9191
executionId = executionIds.head
9292

93-
val (scanned2, skipped2) =
94-
findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
93+
val (scanned2, skipped2) = findColumnBatchStats(session, executionId)
9594
assert(scanned2 == skipped2, "No Column batches should have been scanned")
9695
assert(skipped2 > 0, "No Column batches should have been scanned")
9796

9897
// ***Check for the case when some of the column batches are scanned ****
99-
previousExecutionIds = activeExecutionIds(session)
98+
previousExecutionIds = sqlExecutionIds(session)
10099

101100
val df_someColumnBatchesScan = session.sql(
102101
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
103102
"from AIRLINE where ArrDelay < 20 " +
104103
"group by UniqueCarrier order by arrivalDelay")
105104

106-
df_someColumnBatchesScan.count()
105+
df_someColumnBatchesScan.collect()
107106

108-
executionIds = activeExecutionIds(session).diff(previousExecutionIds)
107+
executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
109108

110109
executionId = executionIds.head
111110

112-
val (scanned3, skipped3) =
113-
findColumnBatchStats(df_allColumnBatchesScan, session, executionId)
111+
val (scanned3, skipped3) = findColumnBatchStats(session, executionId)
114112

115113
assert(skipped3 > 0, "Some Column batches should have been skipped")
116114
assert(scanned3 != skipped3, "Some Column batches should have been skipped - comparison")
117115

118116
// check for StartsWith predicate with MAX/MIN handling
119117

120118
// first all batches chosen
121-
previousExecutionIds = activeExecutionIds(session)
119+
previousExecutionIds = sqlExecutionIds(session)
122120

123121
val df_allColumnBatchesLikeScan = session.sql(
124122
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
125123
"from AIRLINE where UniqueCarrier like 'AA%' " +
126124
"group by UniqueCarrier order by arrivalDelay")
127125

128-
var count = df_allColumnBatchesLikeScan.count()
129-
assert(count == 100, s"Unexpected count = $count, expected 100")
126+
var count = df_allColumnBatchesLikeScan.collect().length
127+
assert(count == 1000, s"Unexpected count = $count, expected 1000")
130128

131-
executionIds = activeExecutionIds(session).diff(previousExecutionIds)
129+
executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
132130

133131
executionId = executionIds.head
134132

135-
val (scanned4, skipped4) =
136-
findColumnBatchStats(df_allColumnBatchesLikeScan, session, executionId)
133+
val (scanned4, skipped4) = findColumnBatchStats(session, executionId)
137134

138135
assert(skipped4 == 0, "No Column batches should have been skipped")
139136
assert(scanned4 > 0, "All Column batches should have been scanned")
140137

141138
// next some batches skipped
142-
previousExecutionIds = activeExecutionIds(session)
139+
previousExecutionIds = sqlExecutionIds(session)
143140

144141
val df_someColumnBatchesLikeScan = session.sql(
145142
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
146143
"from AIRLINE where UniqueCarrier like 'AA1%' " +
147144
"group by UniqueCarrier order by arrivalDelay")
148145

149-
count = df_someColumnBatchesLikeScan.count()
150-
assert(count == 12, s"Unexpected count = $count, expected 12")
146+
count = df_someColumnBatchesLikeScan.collect().length
147+
assert(count == 112, s"Unexpected count = $count, expected 112")
151148

152-
executionIds = activeExecutionIds(session).diff(previousExecutionIds)
149+
executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
153150

154151
executionId = executionIds.head
155152

156-
val (scanned5, skipped5) =
157-
findColumnBatchStats(df_someColumnBatchesLikeScan, session, executionId)
153+
val (scanned5, skipped5) = findColumnBatchStats(session, executionId)
158154

159155
assert(skipped5 > 0, "Some Column batches should have been skipped")
160156
assert(scanned5 != skipped5, "Some Column batches should have been skipped - comparison")
161157

162158
// last all batches skipped
163-
previousExecutionIds = activeExecutionIds(session)
159+
previousExecutionIds = sqlExecutionIds(session)
164160

165161
val df_noColumnBatchesLikeScan = session.sql(
166162
"select AVG(ArrDelay) arrivalDelay, UniqueCarrier carrier " +
167163
"from AIRLINE where UniqueCarrier like 'AA0%' " +
168164
"group by UniqueCarrier order by arrivalDelay")
169165

170-
count = df_noColumnBatchesLikeScan.count()
166+
count = df_noColumnBatchesLikeScan.collect().length
171167
assert(count == 0, s"Unexpected count = $count, expected 0")
172168

173-
executionIds = activeExecutionIds(session).diff(previousExecutionIds)
169+
executionIds = sqlExecutionIds(session).diff(previousExecutionIds)
174170

175171
executionId = executionIds.head
176172

177-
val (scanned6, skipped6) =
178-
findColumnBatchStats(df_noColumnBatchesLikeScan, session, executionId)
173+
val (scanned6, skipped6) = findColumnBatchStats(session, executionId)
179174

180175
assert(scanned6 == skipped6, "No Column batches should have been returned")
181176
assert(skipped6 > 0, "No Column batches should have been returned")
182177
}
183178

184-
private def findColumnBatchStats(df: DataFrame,
185-
session: SnappySession, executionId: Long): (Long, Long) = {
179+
private def getAccumulatorValue(execData: SQLExecutionUIData, name: String): Long = {
180+
execData.metrics.find(_.name == name) match {
181+
case Some(id) => execData.metricValues.get(id.accumulatorId) match {
182+
case Some(v) => v.toLong
183+
case _ => 0L
184+
}
185+
case _ => 0L
186+
}
187+
}
186188

187-
val execData = session.sharedState.statusStore.executionsList().find(
188-
_.executionId == executionId).get
189-
val seenId = execData.metrics.find(_.name == "column batches seen").get
190-
val skippedId = execData.metrics.find(_.name == "column batches skipped by the predicate").get
189+
private def findColumnBatchStats(session: SnappySession, executionId: Long): (Long, Long) = {
190+
var execData: SQLExecutionUIData = null
191+
SnappyFunSuite.waitForCriterion({
192+
execData = session.sharedState.statusStore.executionsList().find(
193+
_.executionId == executionId).get
194+
execData.metricValues ne null
195+
}, s"waiting for metricValues of executionId = $executionId", 10000, 10)
191196

192-
(execData.metricValues.filter(_._1 == seenId).head._2.toInt,
193-
execData.metricValues.filter(_._1 == skippedId).head._2.toInt)
197+
(getAccumulatorValue(execData, "column batches seen"),
198+
getAccumulatorValue(execData, "column batches skipped by the predicate"))
194199
}
195200

196201
def testCreateColumnTablesFromOtherTables(): Unit = {

cluster/src/test/scala/io/snappydata/filodb/FiloDBApp_Column.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright (c) 2017-2019 TIBCO Software Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you
5+
* may not use this file except in compliance with the License. You
6+
* may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License. See accompanying
15+
* LICENSE file.
16+
*/
17+
118
package io.snappydata.filodb
219

320
import scala.concurrent.duration.Duration

cluster/src/test/scala/io/snappydata/filodb/FiloDBApp_Row.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* Copyright (c) 2017-2019 TIBCO Software Inc. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you
5+
* may not use this file except in compliance with the License. You
6+
* may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13+
* implied. See the License for the specific language governing
14+
* permissions and limitations under the License. See accompanying
15+
* LICENSE file.
16+
*/
17+
118
package io.snappydata.filodb
219

320
import java.sql.{DriverManager, PreparedStatement}

core/src/main/scala/org/apache/spark/sql/internal/session.scala

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,17 +288,23 @@ class SnappyConf(@transient val session: SnappySession)
288288

289289
private[sql] def setDynamicCpusPerTask(): Unit = synchronized {
290290
if (dynamicCpusPerTask != -1) {
291+
val numExecutors = SnappyContext.numExecutors
292+
val totalUsableHeap = SnappyContext.foldLeftBlockIds(0L)(_ + _.usableHeapBytes)
293+
294+
// skip for smart connector where there is no information of physical cores or heap
295+
if (numExecutors == 0 || totalUsableHeap <= 0) return
296+
291297
val sparkCores = session.sparkContext.defaultParallelism.toDouble
292298
// calculate minimum required heap assuming a block size of 128M
293299
val minRequiredHeap = 128.0 * 1024.0 * 1024.0 * sparkCores * 1.2
294-
val totalUsableHeap = SnappyContext.foldLeftBlockIds(0L)(_ + _.usableHeapBytes)
300+
295301
// select bigger among (required heap / available) and (logical cores / physical)
296302
val cpusPerTask0 = math.max(minRequiredHeap / totalUsableHeap,
297303
sparkCores / SnappyContext.totalPhysicalCoreCount.get())
298304
// keep a reasonable upper-limit so tasks can at least be scheduled:
299305
// used below is average logical cores / 2
300306
val cpusPerTask = math.max(1, math.ceil(math.min(sparkCores /
301-
(2 * SnappyContext.numExecutors), cpusPerTask0)).toInt)
307+
(2 * numExecutors), cpusPerTask0)).toInt)
302308
setConfString(Constant.CPUS_PER_TASK_PROP, cpusPerTask.toString)
303309
dynamicCpusPerTask = cpusPerTask
304310
logDebug(s"Set dynamic ${Constant.CPUS_PER_TASK_PROP} to $cpusPerTask")
Binary file not shown.
-88 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)