/
taskQueueRecorder.go
72 lines (61 loc) · 1.57 KB
/
taskQueueRecorder.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package decision
import "github.com/SJTU-OpenNetwork/go-peertaskqueue/peertask"
type taskQueueRecorder struct{
blockNumber int64
blockSize int64
maxNumber int64
maxSize int64
}
func(t *taskQueueRecorder) BlockAdd(taskNumber int, blocksize int){
//t.blockSize += task.Tasks
t.blockNumber += int64(taskNumber)
t.blockSize += int64(blocksize)
}
func(t *taskQueueRecorder) BlockAddNumberOnly(taskNumber int){
t.blockNumber += int64(taskNumber)
}
func(t *taskQueueRecorder) BlockPop(task *peertask.TaskBlock){
//task.Tasks
//blockNumber +=
if task == nil {
return
}
if t.blockNumber <= 0{
log.Error("pop when record counts 0 blocks")
return
}
t.blockNumber -= int64(len(task.Tasks))
}
func (t *taskQueueRecorder) RemoveTask(){
if t.blockNumber <= 0{
log.Error("remove when record counts 0 blocks")
return
}
t.blockNumber --
}
/*
* Whether the taskQueue is full.
* return true if the number of blocks or size of blocks extends limit.
*/
func(t *taskQueueRecorder) IsFull() bool{
if t.maxNumber > 0 && t.blockNumber >= t.maxNumber {
return true
}
if t.maxSize > 0 && t.blockSize >= t.maxSize {
return true
}
return false
}
/*
* The predicted complete time for the tasks in task queue.
* It was used to estimate the timestamp of ticket.
* return: the predicted time in millsecond
*/
func (t *taskQueueRecorder) PredictTime() int64 {
//return (t.blockNumber * defaultBlockSize)/
return t.blockNumber * 100
}
func (t *taskQueueRecorder) PredictTimeByNumOfTasks(num int) int64 {
//return (t.blockNumber * defaultBlockSize)/
return int64(num) * 100
}