Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Analyze
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
trinity-1686a
Snowflake
Commits
47e13382
Commit
47e13382
authored
8 years ago
by
Serene H
Browse files
Options
Downloads
Patches
Plain Diff
initial client roundtrip estimate on broker
parent
6cecd31f
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
broker/broker.go
+18
-7
18 additions, 7 deletions
broker/broker.go
broker/metrics.go
+17
-0
17 additions, 0 deletions
broker/metrics.go
client/torrc
+1
-1
1 addition, 1 deletion
client/torrc
proxy/snowflake.coffee
+1
-0
1 addition, 0 deletions
proxy/snowflake.coffee
with
37 additions
and
8 deletions
broker/broker.go
+
18
−
7
View file @
47e13382
...
...
@@ -26,6 +26,7 @@ type BrokerContext struct {
// the second http POST.
idToSnowflake
map
[
string
]
*
Snowflake
proxyPolls
chan
*
ProxyPoll
metrics
*
Metrics
}
func
NewBrokerContext
()
*
BrokerContext
{
...
...
@@ -35,6 +36,7 @@ func NewBrokerContext() *BrokerContext {
snowflakes
:
snowflakes
,
idToSnowflake
:
make
(
map
[
string
]
*
Snowflake
),
proxyPolls
:
make
(
chan
*
ProxyPoll
),
metrics
:
new
(
Metrics
),
}
}
...
...
@@ -67,7 +69,7 @@ func (ctx *BrokerContext) RequestOffer(id string) []byte {
request
.
id
=
id
request
.
offerChannel
=
make
(
chan
[]
byte
)
ctx
.
proxyPolls
<-
request
// Block until an offer is available
..
.
// Block until an offer is available
, or timeout which sends a nil offer
.
offer
:=
<-
request
.
offerChannel
return
offer
}
...
...
@@ -96,6 +98,8 @@ func (ctx *BrokerContext) Broker() {
}
// Create and add a Snowflake to the heap.
// Required to keep track of proxies between providing them
// with an offer and awaiting their second POST with an answer.
func
(
ctx
*
BrokerContext
)
AddSnowflake
(
id
string
)
*
Snowflake
{
snowflake
:=
new
(
Snowflake
)
snowflake
.
id
=
id
...
...
@@ -141,29 +145,32 @@ snowflake proxy, which responds with the SDP answer to be sent in
the HTTP response back to the client.
*/
func
clientOffers
(
ctx
*
BrokerContext
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
startTime
:=
time
.
Now
()
offer
,
err
:=
ioutil
.
ReadAll
(
r
.
Body
)
if
nil
!=
err
{
log
.
Println
(
"Invalid data."
)
w
.
WriteHeader
(
http
.
StatusBadRequest
)
return
}
// Find the most available snowflake proxy, and pass the offer to it.
// TODO: Needs improvement - maybe shouldn't immediately fail?
// Immediately fail if there are no snowflakes available.
if
ctx
.
snowflakes
.
Len
()
<=
0
{
log
.
Println
(
"Client: No snowflake proxies available."
)
w
.
WriteHeader
(
http
.
StatusServiceUnavailable
)
return
}
// Otherwise, find the most available snowflake proxy, and pass the offer to it.
snowflake
:=
heap
.
Pop
(
ctx
.
snowflakes
)
.
(
*
Snowflake
)
defer
delete
(
ctx
.
idToSnowflake
,
snowflake
.
id
)
delete
(
ctx
.
idToSnowflake
,
snowflake
.
id
)
snowflake
.
offerChannel
<-
offer
// Wait for the answer to be returned on the channel.
// Wait for the answer to be returned on the channel
or timeout
.
select
{
case
answer
:=
<-
snowflake
.
answerChannel
:
log
.
Println
(
"Client: Retrieving answer"
)
w
.
Write
(
answer
)
// Initial tracking of elapsed time.
ctx
.
metrics
.
clientRoundtripEstimate
=
time
.
Since
(
startTime
)
/
time
.
Millisecond
case
<-
time
.
After
(
time
.
Second
*
ClientTimeout
)
:
log
.
Println
(
"Client: Timed out."
)
w
.
WriteHeader
(
http
.
StatusGatewayTimeout
)
...
...
@@ -196,7 +203,11 @@ func proxyAnswers(ctx *BrokerContext, w http.ResponseWriter, r *http.Request) {
}
func
debugHandler
(
ctx
*
BrokerContext
,
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
s
:=
fmt
.
Sprintf
(
"current: %d"
,
ctx
.
snowflakes
.
Len
())
s
:=
fmt
.
Sprintf
(
"current snowflakes available: %d
\n
"
,
ctx
.
snowflakes
.
Len
())
for
_
,
snowflake
:=
range
ctx
.
idToSnowflake
{
s
+=
fmt
.
Sprintf
(
"
\n
snowflake %d: %s"
,
snowflake
.
index
,
snowflake
.
id
)
}
s
+=
fmt
.
Sprintf
(
"
\n\n
roundtrip avg: %d"
,
ctx
.
metrics
.
clientRoundtripEstimate
)
w
.
Write
([]
byte
(
s
))
}
...
...
This diff is collapsed.
Click to expand it.
broker/metrics.go
0 → 100644
+
17
−
0
View file @
47e13382
package
snowflake_broker
import
(
// "golang.org/x/net/internal/timeseries"
"time"
)
// Implements Observable
type
Metrics
struct
{
// snowflakes timeseries.Float
clientRoundtripEstimate
time
.
Duration
}
func
NewMetrics
()
*
Metrics
{
m
:=
new
(
Metrics
)
return
m
}
This diff is collapsed.
Click to expand it.
client/torrc
+
1
−
1
View file @
47e13382
...
...
@@ -5,6 +5,6 @@ ClientTransportPlugin snowflake exec ./client \
-url https://snowflake-reg.appspot.com/ \
-front www.google.com \
-ice stun:stun.l.google.com:19302 \
-max
1
-max
3
Bridge snowflake 0.0.3.0:1
This diff is collapsed.
Click to expand it.
proxy/snowflake.coffee
+
1
−
0
View file @
47e13382
...
...
@@ -125,6 +125,7 @@ class Snowflake
try
offer
=
JSON
.
parse
desc
dbg
'Received:
\n\n
'
+
offer
.
sdp
+
'
\n
'
console
.
log
offer
sdp
=
new
SessionDescription
offer
@
sendAnswer
pair
if
pair
.
receiveWebRTCOffer
sdp
catch
e
...
...
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