-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixedConnections.go
38 lines (30 loc) · 1.49 KB
/
fixedConnections.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package crawlrate
import (
"math"
"time"
)
// FixedConnections algorithm favours fixed connection count per proxy over a variable duration.
// This algorithm will tell you the total time duration it will take to complete the keywords
// given the proxies and limiting them to a fixed number of connections.
// If the user supplies a connectionCount greater than that required, then the returned pulse
// will contain a corrected connectionCount (volume).
func FixedConnections(keywordCount, proxyCount, avgJobRuntime, minimumDelay, connectionCount int) (*Pulse, error) {
// Divide the number of keywords between the number of proxies and round
// up. This gives us our keywordCountPerProxy.
keywordCountPerProxy := int(keywordCount / proxyCount)
// Calculate the total number of keywords per channel
keywordsPerChannel := int(math.Ceil(float64(keywordCountPerProxy) / float64(connectionCount)))
/*
x := float64(keywordCountPerProxy) / float64(connectionCount)
fmt.Printf("x: %f keywordsPerChannel: %d\n", x, int(math.Ceil(x)))
*/
// Calculate the total time a keyword will take, including its delay.
totalKeywordTime := avgJobRuntime + minimumDelay
// Determine the total time period required to process all keywords
timePeriod := keywordsPerChannel * totalKeywordTime
return &Pulse{
Volume: int(math.Ceil(float64(keywordCountPerProxy) / float64(keywordsPerChannel))),
Frequency: time.Duration(totalKeywordTime) * time.Second,
Duration: time.Duration(timePeriod) * time.Second,
}, nil
}