memory issues galore

This commit is contained in:
farhan 2020-11-16 00:10:33 -05:00
parent aab707eab0
commit 94334b710b
2 changed files with 20 additions and 10 deletions

View File

@ -28,7 +28,7 @@ func DeferPollRun(instancereport InstanceReport, runninginstances *[]RunningInst
} }
time.Sleep(time.Second * time.Duration(delay)) time.Sleep(time.Second * time.Duration(delay))
go StartInstancePoll(instancereport, reportPostChan, instanceReportChan) StartInstancePoll(instancereport, reportPostChan, instanceReportChan)
} }
func StartInstancePoll(instancereport InstanceReport, reportPostChan chan ReportPost, instanceReportChan chan InstanceReport) { func StartInstancePoll(instancereport InstanceReport, reportPostChan chan ReportPost, instanceReportChan chan InstanceReport) {
@ -45,10 +45,10 @@ func StartInstancePoll(instancereport InstanceReport, reportPostChan chan Report
api_timeline := "https://" + instancereport.endpoint + "/api/v1/timelines/public?limit=40&min_id=" + instancereport.min_id api_timeline := "https://" + instancereport.endpoint + "/api/v1/timelines/public?limit=40&min_id=" + instancereport.min_id
resp, err := http.Get(api_timeline) resp, err := http.Get(api_timeline)
if err != nil { if err != nil {
defer resp.Body.Close()
instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, CLIENT_ISSUE, "", 0}
return return
} }
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
if err != nil { if err != nil {
instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0} instanceReportChan <- InstanceReport{instancereport.endpoint, BAD_RESPONSE, "", 0}
@ -117,9 +117,9 @@ func GetNodeInfo(endpoint string, nodeinfo *NodeInfo) {
http_client := http.Client{Timeout: 5 * time.Second} http_client := http.Client{Timeout: 5 * time.Second}
resp, err := http_client.Get(api_nodeinfo) resp, err := http_client.Get(api_nodeinfo)
if err != nil { if err != nil {
defer resp.Body.Close()
return return
} }
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := ioutil.ReadAll(resp.Body)
err = json.Unmarshal(body, &nodeinfo) err = json.Unmarshal(body, &nodeinfo)

View File

@ -73,8 +73,8 @@ func engine() {
runninginstances := make([]RunningInstance, 0) runninginstances := make([]RunningInstance, 0)
// Initial Setup // Initial Setup
reportPostChan := make(chan ReportPost, 2000) reportPostChan := make(chan ReportPost)
instanceReportChan := make(chan InstanceReport, 20) instanceReportChan := make(chan InstanceReport, 200)
// Setup Database // Setup Database
pool, err := pgxpool.Connect(context.Background(), "postgres://postgres@127.0.0.1/fedilogue") pool, err := pgxpool.Connect(context.Background(), "postgres://postgres@127.0.0.1/fedilogue")
@ -106,15 +106,25 @@ func engine() {
} }
}(l) }(l)
go func() {
for{
v := <-reportPostChan // New Post
fmt.Println(v)
go writePost(pool, v)
}
}()
go func() {
for {
c := <-commandClient // New client connection
go handleClient(c, &runninginstances, instanceReportChan)
}
}()
for { for {
select { select {
case c := <-commandClient: // New client connection
go handleClient(c, &runninginstances, instanceReportChan)
case v := <-reportPostChan: // New Post
go writePost(pool, v)
case w := <-instanceReportChan: // Start or suspend instance case w := <-instanceReportChan: // Start or suspend instance
if w.status == NEW_INSTANCE { if w.status == NEW_INSTANCE {
fmt.Println("The instance: ", x, ", ", len(runninginstances))
x = x + 1 x = x + 1
NewInstance(w.endpoint, &runninginstances, instanceReportChan, reportPostChan) NewInstance(w.endpoint, &runninginstances, instanceReportChan, reportPostChan)
} else if w.status == RUNNING || w.status == TOOMANYREQUESTS { } else if w.status == RUNNING || w.status == TOOMANYREQUESTS {