Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xanadu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
SYNERG
xanadu
Commits
fb27d6a9
Commit
fb27d6a9
authored
Apr 20, 2020
by
Nilanjan Daw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding support for permanent implicit chain metadata
parent
8a33c26a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
233 additions
and
148 deletions
+233
-148
dispatch_system/constants.json
dispatch_system/constants.json
+4
-3
dispatch_system/constants_server.json
dispatch_system/constants_server.json
+40
-0
dispatch_system/dispatch_daemon/execute.js
dispatch_system/dispatch_daemon/execute.js
+18
-7
dispatch_system/dispatch_daemon/index.js
dispatch_system/dispatch_daemon/index.js
+1
-1
dispatch_system/dispatch_daemon/lib.js
dispatch_system/dispatch_daemon/lib.js
+1
-1
dispatch_system/dispatch_manager/explicit_chain_handler.js
dispatch_system/dispatch_manager/explicit_chain_handler.js
+1
-1
dispatch_system/dispatch_manager/index.js
dispatch_system/dispatch_manager/index.js
+5
-8
dispatch_system/dispatch_manager/lib.js
dispatch_system/dispatch_manager/lib.js
+163
-127
No files found.
dispatch_system/constants.json
View file @
fb27d6a9
{
"registry_url"
:
"10.129.6.5:5000/"
,
"master_port"
:
8080
,
"master_address"
:
"
10.129.6.5
"
,
"master_address"
:
"
localhost
"
,
"grunt_host"
:
"https://www.namandixit.net/lovecraftian_nightmares/grunt"
,
"couchdb_host"
:
"10.129.6.5:5984"
,
"db"
:
{
...
...
@@ -12,8 +12,9 @@
},
"network"
:
{
"network_bridge"
:
"hybrid_kafka-serverless"
,
"use_bridge"
:
false
,
"internal"
:
{
"kafka_host"
:
"
kafka
:9092"
"kafka_host"
:
"
10.129.6.5
:9092"
},
"external"
:
{
"kafka_host"
:
"10.129.6.5:9092"
...
...
@@ -34,7 +35,7 @@
"metrics"
:
{
"alpha"
:
0.7
},
"speculative_deployment"
:
fals
e
,
"speculative_deployment"
:
tru
e
,
"JIT_deployment"
:
true
,
"id_size"
:
20
}
dispatch_system/constants_server.json
0 → 100644
View file @
fb27d6a9
{
"registry_url"
:
"10.129.6.5:5000/"
,
"master_port"
:
8080
,
"master_address"
:
"10.129.6.5"
,
"grunt_host"
:
"https://www.namandixit.net/lovecraftian_nightmares/grunt"
,
"couchdb_host"
:
"10.129.6.5:5984"
,
"db"
:
{
"function_meta"
:
"serverless"
,
"metrics"
:
"metrics"
,
"implicit_chain_meta"
:
"implicit_chain"
,
"explicit_chain_meta"
:
"explicit_chain"
},
"network"
:
{
"network_bridge"
:
"hybrid_kafka-serverless"
,
"internal"
:
{
"kafka_host"
:
"kafka:9092"
},
"external"
:
{
"kafka_host"
:
"10.129.6.5:9092"
}
},
"topics"
:
{
"request_dm_2_rm"
:
"request"
,
"heartbeat"
:
"heartbeat"
,
"deployed"
:
"deployed"
,
"remove_worker"
:
"removeWorker"
,
"response_rm_2_dm"
:
"RESPONSE_RM_2_DM_DUMMY"
,
"hscale"
:
"hscale"
,
"log_channel"
:
"LOG_COMMON"
},
"autoscalar_metrics"
:
{
"open_request_threshold"
:
100
},
"metrics"
:
{
"alpha"
:
0.7
},
"speculative_deployment"
:
false
,
"JIT_deployment"
:
true
,
"id_size"
:
20
}
dispatch_system/dispatch_daemon/execute.js
View file @
fb27d6a9
...
...
@@ -92,7 +92,13 @@ function runContainer(metadata) {
if
(
code
!=
0
)
reject
(
"
error
"
)
else
{
const
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
`--network=
${
constants
.
network
.
network_bridge
}
`
,
"
-p
"
,
`
${
port
}
:
${
port
}
`
,
let
process
=
null
;
if
(
constants
.
network
.
use_bridge
)
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
`--network=
${
constants
.
network
.
network_bridge
}
`
,
"
-p
"
,
`
${
port
}
:
${
port
}
`
,
"
--name
"
,
resource_id
,
registry_url
+
imageName
,
resource_id
,
imageName
,
port
,
"
container
"
,
constants
.
network
.
internal
.
kafka_host
]);
else
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
"
-p
"
,
`
${
port
}
:
${
port
}
`
,
"
--name
"
,
resource_id
,
registry_url
+
imageName
,
resource_id
,
imageName
,
port
,
"
container
"
,
constants
.
network
.
internal
.
kafka_host
]);
let
result
=
""
;
...
...
@@ -119,8 +125,13 @@ function runContainer(metadata) {
})
}
else
{
logger
.
info
(
"
container starting at port
"
,
port
);
const
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
`--network=
${
constants
.
network
.
network_bridge
}
`
,
let
process
=
null
;
if
(
constants
.
network
.
use_bridge
)
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
`--network=
${
constants
.
network
.
network_bridge
}
`
,
"
-p
"
,
`
${
port
}
:
${
port
}
`
,
"
--name
"
,
resource_id
,
registry_url
+
imageName
,
resource_id
,
imageName
,
port
,
"
container
"
,
constants
.
network
.
internal
.
kafka_host
]);
else
process
=
spawn
(
'
docker
'
,
[
"
run
"
,
"
--rm
"
,
"
-p
"
,
`
${
port
}
:
${
port
}
`
,
"
--name
"
,
resource_id
,
registry_url
+
imageName
,
resource_id
,
imageName
,
port
,
"
container
"
,
constants
.
network
.
internal
.
kafka_host
]);
let
result
=
""
;
...
...
dispatch_system/dispatch_daemon/index.js
View file @
fb27d6a9
...
...
@@ -158,7 +158,7 @@ function heartbeat() {
topic
:
"
heartbeat
"
,
messages
:
JSON
.
stringify
({
"
address
"
:
node_id
,
"
timestamp
"
:
Date
.
now
()})
}]
producer
.
send
(
payload
,
function
()
{})
producer
.
send
(
payload
,
function
(
cb
)
{})
}
...
...
dispatch_system/dispatch_daemon/lib.js
View file @
fb27d6a9
...
...
@@ -27,7 +27,7 @@ function updateConfig() {
}
function
makeTopic
(
id
)
{
console
.
log
(
"
Using Primary IP
"
,
id
,
"
as topic
"
);
console
.
log
(
"
Using Primary IP
"
,
id
,
"
as topic
"
,
"
publishing to:
"
,
constants
.
network
.
external
.
kafka_host
);
let
client
=
new
kafka
.
KafkaClient
({
kafkaHost
:
constants
.
network
.
external
.
kafka_host
,
...
...
dispatch_system/dispatch_manager/explicit_chain_handler.js
View file @
fb27d6a9
...
...
@@ -254,7 +254,7 @@ async function orchestrator(chain_id, res, payload, map, aliases, result) {
runtime
:
metadata
.
runtime
,
payload
}),
headers
:
{
'
Content-Type
'
:
'
application/json
'
}
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
'
x-chain-type
'
:
'
explicit
'
}
}
delete
map
[
functionName
]
aliases
[
functionName
].
status
=
"
running
"
...
...
dispatch_system/dispatch_manager/index.js
View file @
fb27d6a9
...
...
@@ -219,7 +219,7 @@ app.post('/serverless/execute/:id', (req, res) => {
res
.
timestamp
=
Date
.
now
()
if
(
functionToResource
.
has
(
id
))
{
res
.
start
=
'
warmstart
'
libSupport
.
reverseProxy
(
req
,
res
,
functionToResource
,
resourceMap
,
functionBranchTree
)
libSupport
.
reverseProxy
(
req
,
res
)
}
else
{
res
.
start
=
'
coldstart
'
/**
...
...
@@ -328,17 +328,14 @@ function postDeploy(message) {
"
reason
"
:
"
deployment
"
,
"
status
"
:
true
,
starttime
:
(
Date
.
now
()
-
resource
.
deploy_request_time
)
},
message
.
resource_id
,
resourceMap
)
},
message
.
resource_id
)
if
(
db
.
has
(
id
))
{
let
sendQueue
=
db
.
get
(
id
)
logger
.
info
(
"
forwarding request via reverse proxy to:
"
+
JSON
.
stringify
(
resource
));
while
(
sendQueue
&&
sendQueue
.
length
!=
0
)
{
let
{
req
,
res
}
=
sendQueue
.
shift
()
libSupport
.
reverseProxy
(
req
,
res
,
functionToResource
,
resourceMap
,
functionBranchTree
)
.
then
(()
=>
{
})
libSupport
.
reverseProxy
(
req
,
res
)
}
db
.
delete
(
id
)
}
...
...
@@ -404,7 +401,7 @@ consumer.on('message', function (message) {
"
reason
"
:
"
terminate
"
,
"
total_request
"
:
message
.
total_request
,
"
status
"
:
true
},
message
.
resource_id
,
resourceMap
)
},
message
.
resource_id
)
.
then
(()
=>
{
resourceMap
.
delete
(
message
.
resource_id
)
if
(
resourceArray
.
length
==
0
)
...
...
@@ -557,7 +554,7 @@ async function speculative_deployment(req, runtime) {
}
}
setInterval
(
libSupport
.
metrics
.
broadcastMetrics
,
5000
)
setInterval
(
libSupport
.
viterbi
,
1000
,
functionBranchTree
)
// setInterval(libSupport.viterbi, 1000
)
setInterval
(
autoscalar
,
1000
);
setInterval
(
dispatch
,
1000
);
app
.
listen
(
port
,
()
=>
logger
.
info
(
`Server listening on port
${
port
}
!`
))
\ No newline at end of file
dispatch_system/dispatch_manager/lib.js
View file @
fb27d6a9
...
...
@@ -6,10 +6,18 @@ const winston = require('winston')
const
constants
=
require
(
'
.././constants.json
'
)
const
secrets
=
require
(
'
./secrets.json
'
)
const
metrics
=
require
(
'
./metrics
'
)
const
sharedMeta
=
require
(
'
./shared_meta
'
)
const
{
createLogger
,
format
,
transports
}
=
winston
;
const
heap
=
require
(
'
heap
'
)
let
db
=
sharedMeta
.
db
,
// queue holding request to be dispatched
resourceMap
=
sharedMeta
.
resourceMap
,
// map between resource_id and resource details like node_id, port, associated function etc
functionToResource
=
sharedMeta
.
functionToResource
,
// a function to resource map. Each map contains a minheap of
// resources associated with the function
workerNodes
=
sharedMeta
.
workerNodes
,
// list of worker nodes currently known to the DM
functionBranchTree
=
sharedMeta
.
functionBranchTree
// Holds the function path's and related probability distribution
let
kafka
=
require
(
'
kafka-node
'
),
Producer
=
kafka
.
Producer
,
client
=
new
kafka
.
KafkaClient
({
...
...
@@ -18,9 +26,7 @@ let kafka = require('kafka-node'),
}),
producer
=
new
Producer
(
client
)
let
implicitChainDB
=
`http://
${
secrets
.
couchdb_username
}
:
${
secrets
.
couchdb_password
}
@
${
constants
.
couchdb_host
}
`
implicitChainDB
=
implicitChainDB
+
"
/
"
+
constants
.
implicit_chain_db_names
+
"
/
"
let
implicitChainDB
=
sharedMeta
.
implicitChainDB
/**
* Generates unique IDs of arbitrary length
* @param {Length of the ID} length
...
...
@@ -62,13 +68,10 @@ function generateExecutor(functionPath, functionHash) {
* Reverse proxy to take user requests and forward them to appropriate workers using a loadbalacer
* @param {JSON} req the user request to be forwarded to the worker
* @param {JSON} res Object to use to return the response to the user
* @param {Map} functionToResource Function to resource Map
* @param {Map} resourceMap Map from resource ID to resource metadata
* @param {Map} functionBranchTree Holds the function path's and related probability distribution
*/
function
reverseProxy
(
req
,
res
,
functionToResource
,
resourceMap
,
functionBranchTree
)
{
branchChainPredictor
(
req
,
resourceMap
,
functionToResource
,
functionBranchTree
)
return
new
Promise
((
resolve
,
reject
)
=>
{
function
reverseProxy
(
req
,
res
)
{
if
(
req
.
headers
[
'
x-chain-type
'
]
!==
'
explicit
'
)
branchChainPredictor
(
req
)
let
runtime
=
req
.
body
.
runtime
let
id
=
req
.
params
.
id
+
runtime
/**
...
...
@@ -102,19 +105,36 @@ function reverseProxy(req, res, functionToResource, resourceMap, functionBranchT
res
.
json
(
parsedBody
)
forwardTo
.
open_request_count
-=
1
heap
.
heapify
(
functionHeap
,
compare
)
let
functionHash
=
req
.
params
.
id
let
functionData
=
functionBranchTree
.
get
(
functionHash
)
if
(
functionData
&&
functionData
.
req_count
%
5
==
0
)
{
if
(
functionData
.
parent
)
viterbi
(
functionHash
,
functionData
)
else
{
functionData
.
branches
=
Array
.
from
(
functionData
.
branches
.
entries
())
let
payload
=
{
method
:
'
put
'
,
body
:
JSON
.
stringify
(
functionBranchTree
.
get
(
functionHash
)),
headers
:
{
'
Content-Type
'
:
'
application/json
'
}
}
fetchData
(
implicitChainDB
+
functionHash
,
payload
)
.
then
((
updateStatus
)
=>
{
console
.
log
(
updateStatus
);
if
(
updateStatus
.
error
===
undefined
)
functionData
.
_rev
=
updateStatus
.
rev
})
functionData
.
branches
=
new
Map
(
functionData
.
branches
)
}
}
metrics
.
collectMetrics
({
type
:
res
.
start
,
value
:
serviceTime
,
functionHash
:
req
.
params
.
id
,
runtime
})
resolve
()
})
.
catch
(
function
(
err
)
{
forwardTo
.
open_request_count
-=
1
heap
.
heapify
(
functionHeap
,
compare
)
logger
.
error
(
"
error
"
+
err
);
res
.
json
(
err
.
message
).
status
(
err
.
statusCode
)
resolve
()
});
})
}
function
getPort
(
usedPort
)
{
...
...
@@ -161,10 +181,20 @@ function compare(a, b) {
return
a
.
open_request_count
-
b
.
open_request_count
}
function
branchChainPredictor
(
req
,
resourceMap
,
functionToResource
,
functionBranchTree
)
{
async
function
branchChainPredictor
(
req
)
{
// console.log(req.headers['x-resource-id']);
if
(
!
functionBranchTree
.
has
(
req
.
params
.
id
))
{
let
data
=
await
fetchData
(
implicitChainDB
+
req
.
params
.
id
)
if
(
data
.
error
===
"
not_found
"
)
console
.
log
(
"
no data
"
,
req
.
params
.
id
);
else
{
data
.
branches
=
new
Map
(
data
.
branches
)
functionBranchTree
.
set
(
req
.
params
.
id
,
data
)
}
}
if
(
req
.
headers
[
'
x-resource-id
'
]
===
undefined
)
{
let
functionHash
=
req
.
params
.
id
if
(
functionBranchTree
.
has
(
functionHash
))
{
let
branchInfo
=
functionBranchTree
.
get
(
functionHash
)
...
...
@@ -215,18 +245,16 @@ function branchChainPredictor(req, resourceMap, functionToResource, functionBran
// console.log("branch tree", functionBranchTree);
}
function
viterbi
(
functionBranchTree
)
{
functionBranchTree
.
forEach
((
metadata
,
node
)
=>
{
if
(
metadata
.
parent
&&
metadata
.
req_count
%
5
==
0
)
{
async
function
viterbi
(
node
,
metadata
)
{
console
.
log
(
"
function branch tree
"
,
functionBranchTree
.
get
(
node
));
let
path
=
[]
let
parents
=
[[
node
,
{
prob
:
1
,
metadata
}]]
path
.
push
({
node
,
probability
:
1
})
path
.
push
({
node
,
probability
:
1
})
let
siblings
=
new
Map
()
while
(
parents
.
length
>
0
)
{
while
(
parents
.
length
>
0
)
{
// console.log("parent_group", parents);
for
(
const
parent
of
parents
)
{
...
...
@@ -260,7 +288,7 @@ function viterbi(functionBranchTree) {
maxProb
=
prob
}
})
parentIDs
=
Array
.
from
(
siblings
.
keys
()
);
parentIDs
=
Array
.
from
(
siblings
.
keys
()
);
for
(
const
id
of
parentIDs
)
{
let
metadata
=
functionBranchTree
.
get
(
id
)
parents
.
push
([
...
...
@@ -271,25 +299,33 @@ function viterbi(functionBranchTree) {
])
}
if
(
maxSibling
!==
undefined
)
path
.
push
({
node
:
maxSibling
,
probability
:
maxProb
})
path
.
push
({
node
:
maxSibling
,
probability
:
maxProb
})
siblings
=
new
Map
()
}
// if (path.length > 0)
// console.log("path", path);
if
(
path
.
length
>
1
)
console
.
log
(
"
path
"
,
path
);
metadata
.
mle_path
=
path
if
(
path
.
length
>
1
)
{
metadata
.
branches
=
Array
.
from
(
metadata
.
branches
.
entries
())
let
payload
=
{
method
:
'
put
'
,
body
:
JSON
.
stringify
(
path
),
body
:
JSON
.
stringify
(
functionBranchTree
.
get
(
node
)
),
headers
:
{
'
Content-Type
'
:
'
application/json
'
}
}
fetch
(
implicitChainDB
+
functionHash
,
payload
)
}
fetchData
(
implicitChainDB
+
node
,
payload
)
.
then
((
updateStatus
)
=>
{
console
.
log
(
updateStatus
);
if
(
updateStatus
.
error
===
undefined
)
metadata
.
_rev
=
updateStatus
.
rev
})
metadata
.
branches
=
new
Map
(
metadata
.
branches
)
}
});
}
function
logBroadcast
(
message
,
resource_id
,
resourceMap
)
{
function
logBroadcast
(
message
,
resource_id
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
try
{
...
...
@@ -329,6 +365,6 @@ async function fetchData(url, data = null) {
module
.
exports
=
{
makeid
,
generateExecutor
,
reverseProxy
,
getPort
,
logger
,
compare
,
viterbi
,
logBroadcast
,
fetchData
,
metrics
,
logBroadcast
,
fetchData
,
metrics
,
producer
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment