Added runtime.Gosched for context switching

This commit is contained in:
Trial97
2020-09-29 15:54:28 +03:00
committed by Dan Christian Bogos
parent 8e3ca35a77
commit e1086b099a
7 changed files with 16 additions and 12 deletions

View File

@@ -28,6 +28,7 @@ import (
"net/url"
"os"
"path/filepath"
"runtime"
"strings"
"sync"
"time"
@@ -1406,7 +1407,7 @@ func (cfg *CGRConfig) reloadSections(sections ...string) (err error) {
break
}
}
time.Sleep(1)
runtime.Gosched()
for _, section := range sections {
switch section {
default:

View File

@@ -22,8 +22,8 @@ package engine
import (
"net/rpc"
"path"
"runtime"
"testing"
"time"
"github.com/cgrates/cgrates/config"
"github.com/cgrates/cgrates/utils"
@@ -269,7 +269,7 @@ func testActionsUpdateBalance(t *testing.T) {
} else if reply != utils.OK {
t.Errorf("Calling APIerSv1.ExecuteAction received: %s", reply)
}
time.Sleep(1)
runtime.Gosched()
attrsEA2 := &utils.AttrExecuteAction{Tenant: attrsSetAccount.Tenant, Account: attrsSetAccount.Account, ActionsId: changeBlockerAction.ActionsId}
if err := actsRPC.Call(utils.APIerSv1ExecuteAction, attrsEA2, &reply); err != nil {
t.Error("Got error on APIerSv1.ExecuteAction: ", err.Error())

View File

@@ -21,6 +21,7 @@ package engine
import (
"encoding/gob"
"fmt"
"runtime"
"sync"
"time"
@@ -104,8 +105,8 @@ func (chS *CacheS) Precache() (err error) {
wg.Done()
}(cacheID)
}
time.Sleep(1) // switch context
go func() { // report wg.Wait on doneChan
runtime.Gosched() // switch context
go func() { // report wg.Wait on doneChan
wg.Wait()
close(doneChan)
}()

View File

@@ -20,8 +20,8 @@ package services
import (
"fmt"
"runtime"
"sync"
"time"
v1 "github.com/cgrates/cgrates/apier/v1"
"github.com/cgrates/cgrates/config"
@@ -111,7 +111,7 @@ func (apiService *APIerSv1Service) Start() (err error) {
// erS.exitChan <- true
}
}(apiService.api, apiService.syncStop)
time.Sleep(1)
runtime.Gosched()
if !apiService.cfg.DispatcherSCfg().Enabled {
apiService.server.RpcRegister(apiService.api)

View File

@@ -20,8 +20,8 @@ package services
import (
"fmt"
"runtime"
"sync"
"time"
v1 "github.com/cgrates/cgrates/apier/v1"
v2 "github.com/cgrates/cgrates/apier/v2"
@@ -95,7 +95,7 @@ func (cdrService *CDRServer) Start() (err error) {
// erS.exitChan <- true
}
}(cdrService.cdrS, cdrService.syncStop)
time.Sleep(1)
runtime.Gosched()
utils.Logger.Info("Registering CDRS HTTP Handlers.")
cdrService.cdrS.RegisterHandlersToServer(cdrService.server)
utils.Logger.Info("Registering CDRS RPC service.")

View File

@@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>
package sessions
import (
"runtime"
"sync"
"time"
@@ -246,7 +247,7 @@ func (s *Session) stopSTerminator() {
func (s *Session) stopDebitLoops() {
if s.debitStop != nil {
close(s.debitStop) // Stop automatic debits
time.Sleep(1)
runtime.Gosched()
s.debitStop = nil
}
}

View File

@@ -23,6 +23,7 @@ import (
"fmt"
"math/rand"
"reflect"
"runtime"
"strings"
"sync"
"time"
@@ -309,7 +310,7 @@ func (sS *SessionS) setSTerminator(s *Session) {
s.sTerminator.timer.Stop()
}
}()
time.Sleep(1) // force context switching
runtime.Gosched() // force context switching
}
// forceSTerminate is called when a session times-out or it is forced from CGRateS side
@@ -1274,7 +1275,7 @@ func (sS *SessionS) initSessionDebitLoops(s *Session) {
s.debitStop = make(chan struct{})
}
go sS.debitLoopSession(s, i, s.DebitInterval)
time.Sleep(1) // allow the goroutine to be executed
runtime.Gosched() // allow the goroutine to be executed
}
}
}