Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
spark
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cs525-sp18-g07
spark
Commits
7b25ab87
Commit
7b25ab87
authored
14 years ago
by
Matei Zaharia
Browse files
Options
Downloads
Patches
Plain Diff
Added options for using an external HTTP server with LocalFileShuffle
parent
504f839c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/scala/spark/HttpServer.scala
+1
-12
1 addition, 12 deletions
src/scala/spark/HttpServer.scala
src/scala/spark/LocalFileShuffle.scala
+28
-7
28 additions, 7 deletions
src/scala/spark/LocalFileShuffle.scala
src/scala/spark/Utils.scala
+12
-0
12 additions, 0 deletions
src/scala/spark/Utils.scala
with
41 additions
and
19 deletions
src/scala/spark/HttpServer.scala
+
1
−
12
View file @
7b25ab87
...
...
@@ -61,18 +61,7 @@ class HttpServer(resourceBase: File) extends Logging {
if
(
server
==
null
)
{
throw
new
ServerStateException
(
"Server is not started"
)
}
else
{
return
"http://"
+
getL
ocalIpAddress
+
":"
+
port
return
"http://"
+
Utils
.
l
ocalIpAddress
+
":"
+
port
}
}
/**
* Get the local host's IP address in dotted-quad format (e.g. 1.2.3.4)
*/
private
def
getLocalIpAddress
:
String
=
{
// Get local IP as an array of four bytes
val
bytes
=
InetAddress
.
getLocalHost
().
getAddress
()
// Convert the bytes to ints (keeping in mind that they may be negative)
// and join them into a string
return
bytes
.
map
(
b
=>
(
b
.
toInt
+
256
)
%
256
).
mkString
(
"."
)
}
}
This diff is collapsed.
Click to expand it.
src/scala/spark/LocalFileShuffle.scala
+
28
−
7
View file @
7b25ab87
...
...
@@ -97,19 +97,24 @@ object LocalFileShuffle extends Logging {
private
var
nextShuffleId
=
new
AtomicLong
(
0
)
// Variables initialized by initializeIfNeeded()
private
var
local
Dir
:
File
=
null
private
var
shuffle
Dir
:
File
=
null
private
var
server
:
HttpServer
=
null
private
var
serverUri
:
String
=
null
private
def
initializeIfNeeded
()
=
synchronized
{
if
(!
initialized
)
{
// TODO: localDir should be created by some mechanism common to Spark
// so that it can be shared among shuffle, broadcast, etc
val
localDirRoot
=
System
.
getProperty
(
"spark.local.dir"
,
"/tmp"
)
var
tries
=
0
var
foundLocalDir
=
false
var
localDir
:
File
=
null
var
localDirUuid
:
UUID
=
null
while
(!
foundLocalDir
&&
tries
<
10
)
{
tries
+=
1
try
{
localDir
=
new
File
(
localDirRoot
,
"spark-local-"
+
UUID
.
randomUUID
())
localDirUuid
=
UUID
.
randomUUID
()
localDir
=
new
File
(
localDirRoot
,
"spark-local-"
+
localDirUuid
)
if
(!
localDir
.
exists
())
{
localDir
.
mkdirs
()
foundLocalDir
=
true
...
...
@@ -123,17 +128,33 @@ object LocalFileShuffle extends Logging {
logError
(
"Failed 10 attempts to create local dir in "
+
localDirRoot
)
System
.
exit
(
1
)
}
logInfo
(
"Local dir: "
+
localDir
)
server
=
new
HttpServer
(
localDir
)
server
.
start
()
serverUri
=
server
.
uri
shuffleDir
=
new
File
(
localDir
,
"shuffle"
)
shuffleDir
.
mkdirs
()
logInfo
(
"Shuffle dir: "
+
shuffleDir
)
val
extServerPort
=
System
.
getProperty
(
"spark.localFileShuffle.external.server.port"
,
"-1"
).
toInt
if
(
extServerPort
!=
-
1
)
{
// We're using an external HTTP server; set URI relative to its root
var
extServerPath
=
System
.
getProperty
(
"spark.localFileShuffle.external.server.path"
,
""
)
if
(
extServerPath
!=
""
&&
!
extServerPath
.
endsWith
(
"/"
))
{
extServerPath
+=
"/"
}
serverUri
=
"http://%s:%d/%s/spark-local-%s"
.
format
(
Utils
.
localIpAddress
,
extServerPort
,
extServerPath
,
localDirUuid
)
}
else
{
// Create our own server
server
=
new
HttpServer
(
localDir
)
server
.
start
()
serverUri
=
server
.
uri
}
initialized
=
true
}
}
def
getOutputFile
(
shuffleId
:
Long
,
inputId
:
Int
,
outputId
:
Int
)
:
File
=
{
initializeIfNeeded
()
val
dir
=
new
File
(
localDir
,
"
shuffle
/"
+
shuffleId
+
"/"
+
inputId
)
val
dir
=
new
File
(
shuffle
Dir
,
shuffleId
+
"/"
+
inputId
)
dir
.
mkdirs
()
val
file
=
new
File
(
dir
,
""
+
outputId
)
return
file
...
...
This diff is collapsed.
Click to expand it.
src/scala/spark/Utils.scala
+
12
−
0
View file @
7b25ab87
package
spark
import
java.io._
import
java.net.InetAddress
import
java.util.UUID
import
scala.collection.mutable.ArrayBuffer
...
...
@@ -112,4 +113,15 @@ object Utils {
}
buf
}
/**
* Get the local host's IP address in dotted-quad format (e.g. 1.2.3.4)
*/
def
localIpAddress
()
:
String
=
{
// Get local IP as an array of four bytes
val
bytes
=
InetAddress
.
getLocalHost
().
getAddress
()
// Convert the bytes to ints (keeping in mind that they may be negative)
// and join them into a string
return
bytes
.
map
(
b
=>
(
b
.
toInt
+
256
)
%
256
).
mkString
(
"."
)
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment