Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
69cfdad
add mesh; mesh handler todo
915604903T Feb 18, 2023
f0bebea
debugging
915604903T Feb 19, 2023
9310e08
modify some details for range map
915604903T Feb 19, 2023
e779446
avoid the same mesh merge in two goroutine
915604903T Feb 19, 2023
7beef81
make pose inv
915604903T Feb 20, 2023
0fecefe
debugging mesh url
915604903T Feb 20, 2023
f78b9a4
debugging mesh url
Fvoiretryzig Feb 20, 2023
97cd531
debugging
915604903T Feb 20, 2023
527edc5
debugging
Fvoiretryzig Feb 20, 2023
aa46f08
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 20, 2023
f76e8e8
debugging
915604903T Feb 20, 2023
939de1d
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 20, 2023
c5c651a
debugging
915604903T Feb 20, 2023
de56f0a
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 20, 2023
7e8acc8
debugging
915604903T Feb 20, 2023
f8d54a9
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 20, 2023
4399223
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 20, 2023
de643e8
debugging
915604903T Feb 20, 2023
b38967a
fixed a name bug
915604903T Feb 20, 2023
a8ee000
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
b49ffb6
fixed sceneMesh save bug
915604903T Feb 21, 2023
4d1707b
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
b7dc11b
if relocalise program failed, not add to failed lsit
915604903T Feb 21, 2023
59d6de4
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
a33cd91
add debug info
Fvoiretryzig Feb 21, 2023
ed0b6c9
add debug info
915604903T Feb 21, 2023
0655af2
add debug info
915604903T Feb 21, 2023
3172054
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
ac0964d
debug
915604903T Feb 21, 2023
3fb348b
debugging
915604903T Feb 21, 2023
8819ddf
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
da4f32e
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
3082c66
debugging
915604903T Feb 21, 2023
4b676bb
debugging
915604903T Feb 21, 2023
cf8e344
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 21, 2023
101d13e
fixed a for bug
Fvoiretryzig Feb 21, 2023
c9619c8
debugging
Fvoiretryzig Feb 22, 2023
c0cd90f
add vis arr in bfs to avoid visited node adding to the path
Fvoiretryzig Feb 22, 2023
b3722dc
add vis arr in bfs to avoid visited node adding to the path
915604903T Feb 22, 2023
4967401
Merge branch 'mesh' of https://github.com/915604903T/CenterServer int…
Fvoiretryzig Feb 22, 2023
7f6d41e
maybe finish
Fvoiretryzig Feb 22, 2023
6f80598
add compress pic when send to client
915604903T Feb 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Binary file modified CenterServer
Binary file not shown.
Binary file added CenterServer.exe
Binary file not shown.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ go 1.17

require (
github.com/gorilla/mux v1.8.0
github.com/shirou/gopsutil/v3 v3.23.1
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646
)

require (
github.com/NVIDIA/go-nvml v0.12.0-0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/shirou/gopsutil/v3 v3.23.1 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
github.com/tklauser/numcpus v0.6.0 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
Expand Down
21 changes: 17 additions & 4 deletions handlers/chooseClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,19 @@ func chooseSequentialClient() int {
return int(atomic.LoadInt32(&nowClient)) % clientCnt
}

func scoreMeshClient(id int) float64 {
// do not consider gpu in this cpu task
score := 0.0
resourceInfoLock.RLock()
resourceInfo := ClientResourceStats[id]
resourceInfoLock.RUnlock()
score += float64(resourceInfo.MemoryFree) / 1e9
for _, cpu := range resourceInfo.CpuUsage {
score += 1 - cpu
}
return score
}

func scoreRelocClient(id int) float64 {
score := 0.0
resourceInfoLock.RLock()
Expand All @@ -19,14 +32,14 @@ func scoreRelocClient(id int) float64 {
return -100.0
}
score += float64(resourceInfo.MemoryFree) / 1e9
score += float64(resourceInfo.GPUMemoryFree) / 1e9
score += float64(resourceInfo.GPUMemoryFree) / 1e7
for _, cpu := range resourceInfo.CpuUsage {
score += 1 - cpu
}
return score
}

func scoreClient(id int) float64 {
func scoreRenderClient(id int) float64 {
score := 0.0
resourceInfoLock.RLock()
resourceInfo := ClientResourceStats[id]
Expand All @@ -35,7 +48,7 @@ func scoreClient(id int) float64 {
return -100.0
}
score += float64(resourceInfo.MemoryFree) / 1e9
score += float64(resourceInfo.GPUMemoryFree) / 1e9
score += float64(resourceInfo.GPUMemoryFree) / 1e7
for _, cpu := range resourceInfo.CpuUsage {
score += 1 - cpu
}
Expand All @@ -46,7 +59,7 @@ func chooseResourceClient() int {
maxScore := 0.0
maxIndex := -1
for i := 0; i < clientCnt; i++ {
score := scoreClient(i)
score := scoreRenderClient(i)
log.Println("[chooseResourceClient] this is ", i, " client score: ", score)
if score > maxScore {
maxIndex = i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package handlers
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strconv"

Expand All @@ -12,12 +11,11 @@ import (

func MakeClientResourceInfoHandler() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
log.Print("[MakeClientResourceInfoHandler] receive client resource")
defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body)

id, _ := strconv.Atoi(mux.Vars(r)["id"])
// log.Print("[MakeClientResourceInfoHandler]", id, "client resource: ", string(body))
// log.Println("[MakeClientResourceInfoHandler] receive", id, "client resource")
resourceInfo := ResourceInfo{}
err := json.Unmarshal(body, &resourceInfo)
if err != nil {
Expand Down
53 changes: 53 additions & 0 deletions handlers/globalVariable.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package handlers

import "sync"

const clientCnt int = 2

// client network info
var Client1Ip, Client2Ip string
var Client1Port, Client2Port string
var ClientAddrs []string
var ClientIpsMap map[string]int

// client resource info
var ClientResourceStats [clientCnt]ResourceInfo
var resourceInfoLock sync.RWMutex

// give info about which clients a specific scene locates (one scene can locate multiple client)
var ClientScenes map[string]map[int]bool
var ClientScenesLock sync.RWMutex

// record failed scene pair in order to generate more possible candidate
var FailedSceneList map[string]map[string]int

// Scene prepare to relocalise
var ProcessingScenesList []string
var ProcessingScenesIndex map[string]int // help ProcessingScenesList to delete scene
var ScenesListLock sync.RWMutex

// prevent running the same scene pair at the same time
var RunningScenePairs map[scenePair]bool
var RunningScenePairsLock sync.RWMutex

var sceneUnion UnionSet
var sceneUnionLock sync.Mutex

var sceneGraph map[string]map[string]Pose // does not have circle in graph
var sceneGraphLock sync.RWMutex

// find the corresponding mesh of a specific scene
var sceneMesh map[string]*MeshInfo
var sceneMeshLock sync.RWMutex

var RunningMeshes map[*MeshInfo]bool
var RunningMeshesLock sync.RWMutex

// for random choose client usage
var nowClient int32 = -1

// generate scene pair candidates number
const candidateNum int = 5

var RelocaliseCntLock sync.Mutex
var RelocaliseCnt = 0
78 changes: 10 additions & 68 deletions handlers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,13 @@ package handlers

import (
"math/rand"
"sync"
"time"
)

const clientCnt int = 2

var Client1Ip, Client2Ip string
var Client1Port, Client2Port string

var ClientAddrs []string
var ClientIpsMap map[string]int
var ClientResourceStats [clientCnt]ResourceInfo

var ClientScenes map[string]map[int]bool

var globalPoses map[scenePair][2]pose

var ProcessingScenesList []string
var ProcessingScenesIndex map[string]int

type scenePair struct {
scene1, scene2 string
}

var RunningScenePairs map[scenePair]bool

var SucceedSceneList []string

var FailedSceneList map[string]map[string]int

var ScenesListLock sync.RWMutex
var globalPoseLock sync.RWMutex
var resourceInfoLock sync.RWMutex
var ClientScenesLock sync.RWMutex
var RunningScenePairsLock sync.RWMutex

var nowClient int32 = -1

const candidateNum int = 10

type pose [4][2]float64

type globalPose struct {
Scene1Name string `json:"scene1name"`
Scene1Ip string `json:"scene1ip"`
Scene1Pose pose `json:"scene1pose"`
Scene2Name string `json:"scene2name"`
Scene2Ip string `json:"scene2ip"`
Scene2Pose pose `json:"scene2pose"`
}

type relocaliseInfo struct {
Scene1Name string `json:"scene1name"`
Scene1IP string `json:"scene1ip"`
Scene2Name string `json:"scene2name"`
Scene2IP string `json:"scene2ip"`
}

type ResourceInfo struct {
GPUMemoryFree uint64 `json:"gpumemoryfree"`
MemoryFree uint64 `json:"memoryfree"`
CpuUsage []float64 `json:"cpuusage"`
}

func init() {
Client1Ip = "127.0.0.1"
Client1Ip = "210.28.134.72"
Client1Port = "23334"
Client2Ip = "127.0.0.1"
Client2Ip = "210.28.134.72"
Client2Port = "23335"

ClientAddrs = []string{}
Expand All @@ -84,16 +23,19 @@ func init() {

ClientScenes = make(map[string]map[int]bool) // save where the scene locate

RunningScenePairs = make(map[scenePair]bool)
FailedSceneList = make(map[string]map[string]int)

ProcessingScenesList = []string{}
ProcessingScenesIndex = make(map[string]int)

SucceedSceneList = []string{}
RunningScenePairs = make(map[scenePair]bool)

FailedSceneList = make(map[string]map[string]int)
globalPoses = make(map[scenePair][2]pose)
sceneUnion = NewUnionSet()
sceneGraph = make(map[string]map[string]Pose)

rand.Seed(time.Now().Unix())
sceneMesh = make(map[string]*MeshInfo)

RunningMeshes = make(map[*MeshInfo]bool)

rand.Seed(time.Now().Unix())
}
109 changes: 109 additions & 0 deletions handlers/matrix.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package handlers

import (
"math"
)

type Matrix struct {
//矩阵结构
N, M int //m是列数,n是⾏数
Data [][]float64
}

func Mul(a [4][4]float64, b [4][4]float64) [4][4]float64 {
res := [4][4]float64{}
for i := 0; i < 4; i++ {
t := [4]float64{}
for j := 0; j < 4; j++ {
r := float64(0)
for k := 0; k < 4; k++ {
r += a[i][k] * b[k][j]
}
t[j] = r
}
res[i] = t
}
return res
}

func Det(Matrix [4][4]float64, N int) float64 {
var T0, T1, T2, Cha int
var Num float64
var B [4][4]float64

if N > 0 {
Cha = 0
for i := 0; i < N; i++ {
var tmpArr [4]float64
for j := 0; j < N; j++ {
tmpArr[j] = 0
}
B[i] = tmpArr
}
Num = 0
for T0 = 0; T0 <= N; T0++ { //T0循环
for T1 = 1; T1 <= N; T1++ { //T1循环
for T2 = 0; T2 <= N-1; T2++ { //T2循环
if T2 == T0 {
Cha = 1
}
B[T1-1][T2] = Matrix[T1][T2+Cha]
} //T2循环
Cha = 0
} //T1循环
Num = Num + Matrix[0][T0]*Det(B, N-1)*math.Pow(-1, float64(T0))
} //T0循环
return Num
} else if N == 0 {
return Matrix[0][0]
}
return 0
}

func Inverse(S1 [4][4]float64) (MatrixC [4][4]float64) {
N := 4 - 1
Matrix := S1
var T0, T1, T2, T3 int
var B [4][4]float64
for i := 0; i < N; i++ {
var tmpArr [4]float64
for j := 0; j < N; j++ {
tmpArr[j] = 0
}
B[i] = tmpArr
}

for i := 0; i < N+1; i++ {
var tmpArr [4]float64
for j := 0; j < N+1; j++ {
tmpArr[j] = 0
}
MatrixC[i] = tmpArr
}

Chay := 0
Chax := 0
add := 1 / Det(Matrix, N)
for T0 = 0; T0 <= N; T0++ {
for T3 = 0; T3 <= N; T3++ {
for T1 = 0; T1 <= N-1; T1++ {
if T1 < T0 {
Chax = 0
} else {
Chax = 1
}
for T2 = 0; T2 <= N-1; T2++ {
if T2 < T3 {
Chay = 0
} else {
Chay = 1
}
B[T1][T2] = Matrix[T1+Chax][T2+Chay]
} //T2循环
} //T1循环
Det(B, N-1)
MatrixC[T3][T0] = Det(B, N-1) * add * (math.Pow(-1, float64(T0+T3)))
}
}
return MatrixC
}
Loading