Skip to content
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

[SPARK-19956][Core]Optimize a location order of blocks with topology information #17300

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,15 @@ private[spark] class BlockManager(

/**
* Return a list of locations for the given block, prioritizing the local machine since
* multiple block managers can share the same host.
* multiple block managers can share the same host, followed by hosts on the same rack.
*/
private def getLocations(blockId: BlockId): Seq[BlockManagerId] = {
val locs = Random.shuffle(master.getLocations(blockId))
val (preferredLocs, otherLocs) = locs.partition { loc => blockManagerId.host == loc.host }
preferredLocs ++ otherLocs
val (sameRackLocs, differentRackLocs) = otherLocs.partition {
loc => blockManagerId.topologyInfo == loc.topologyInfo
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If blockManagerId.topologyInfo is None, we will prefer the locations with empty topologyInfo. It is slightly different with what the shuffling wants to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified, thanks a lot for the good advice.

}
preferredLocs ++ sameRackLocs ++ differentRackLocs
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ class BlockManagerSuite extends SparkFunSuite with Matchers with BeforeAndAfterE
assert(list2DiskGet.get.readMethod === DataReadMethod.Disk)
}

test("optimize a location order of blocks") {
test("optimize a location order of blocks without topology information") {
val localHost = Utils.localHostName()
val otherHost = "otherHost"
val bmMaster = mock(classOf[BlockManagerMaster])
Expand All @@ -497,7 +497,30 @@ class BlockManagerSuite extends SparkFunSuite with Matchers with BeforeAndAfterE
val blockManager = makeBlockManager(128, "exec", bmMaster)
val getLocations = PrivateMethod[Seq[BlockManagerId]]('getLocations)
val locations = blockManager invokePrivate getLocations(BroadcastBlockId(0))
assert(locations.map(_.host).toSet === Set(localHost, localHost, otherHost))
assert(locations.map(_.host) === Seq(localHost, localHost, otherHost))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should also be Seq.

}

test("optimize a location order of blocks with topology information") {
val localHost = Utils.localHostName()
val otherHost = "otherHost"
val localRack = "localRack"
val otherRack = "otherRack"

val bmMaster = mock(classOf[BlockManagerMaster])
val bmId1 = BlockManagerId("id1", localHost, 1, Some(localRack))
val bmId2 = BlockManagerId("id2", localHost, 2, Some(localRack))
val bmId3 = BlockManagerId("id3", otherHost, 3, Some(otherRack))
val bmId4 = BlockManagerId("id4", otherHost, 4, Some(otherRack))
val bmId5 = BlockManagerId("id5", otherHost, 5, Some(localRack))
when(bmMaster.getLocations(mc.any[BlockId]))
.thenReturn(Seq(bmId1, bmId2, bmId5, bmId3, bmId4))

val blockManager = makeBlockManager(128, "exec", bmMaster)
val getLocations = PrivateMethod[Seq[BlockManagerId]]('getLocations)
val locations = blockManager invokePrivate getLocations(BroadcastBlockId(0))
assert(locations.map(_.host) === Seq(localHost, localHost, otherHost, otherHost, otherHost))
assert(locations.flatMap(_.topologyInfo)
=== Seq(localRack, localRack, localRack, otherRack, otherRack))
}

test("SPARK-9591: getRemoteBytes from another location when Exception throw") {
Expand Down