zoukankan      html  css  js  c++  java
  • go xorm,负载均衡

    创建引擎组时,我们可以指示特殊的负载平衡策略。xorm上有5个负载平衡。它们是RandomPolicyWeightRandomPolicyRoundRobinPolicyWeightRoundRobinPolicyLeastConnPolicy您还可以根据GroupPolicy界面实施自己的策略

    • 随机政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/xorm"
    )
    
    var eg *xorm.EngineGroup
    
    func main() {
    	conns := []string{
    		"postgres://postgres:root@localhost:5432/test?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test1?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test2?sslmode=disable",
    	}
        
        var err error
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.RandomPolicy())
    }
    
    • 权重随机政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/xorm"
    )
    
    var eg *xorm.EngineGroup
    
    func main() {
        conns := []string{
    		"postgres://postgres:root@localhost:5432/test?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test1?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test2?sslmode=disable",
    	}
        
    	var err error
    	// set the weights
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRandomPolicy([]int{2, 3}))
    }
    
    • RoundRobinPolicy
    import (
        _ "github.com/lib/pq"
        "xorm.io/xorm"
    )
    
    var eg *xorm.EngineGroup
    
    func main() {
        conns := []string{
    		"postgres://postgres:root@localhost:5432/test?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test1?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test2?sslmode=disable",
    	}
        
        var err error
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.RoundRobinPolicy())
    }
    
    • WeightRoundRobinPolicy
    import (
        _ "github.com/lib/pq"
        "xorm.io/xorm"
    )
    
    var eg *xorm.EngineGroup
    
    func main() {
        conns := []string{
    		"postgres://postgres:root@localhost:5432/test?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test1?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test2?sslmode=disable",
    	}
        
        var err error
        // set the weights
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.WeightRoundRobinPolicy([]int{2, 3}))
    }
    
    • 最低Conn政策
    import (
        _ "github.com/lib/pq"
        "xorm.io/xorm"
    )
    
    var eg *xorm.EngineGroup
    
    func main() {
        conns := []string{
    		"postgres://postgres:root@localhost:5432/test?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test1?sslmode=disable;",
    		"postgres://postgres:root@localhost:5432/test2?sslmode=disable",
    	}
        
        var err error
    	eg, err = xorm.NewEngineGroup("postgres", conns, xorm.LeastConnPolicy())
    }
  • 相关阅读:
    Blazor 服务端组件 Render, RenderFragment ,RenderTreeBuilder, CascadingValue/CascadingParameter
    Git Submodule管理项目子模块
    使用Try.NET创建可交互.NET文档
    开包即食的教程带你浅尝最新开源的C# Web引擎 Blazor
    搞懂Xamarin.Forms布局,看这篇应该就够了吧
    【译】.NET 跨平台界面框架和为什么你首先要考虑再三
    Roslyn 语法树中的各种语法节点及每个节点的含义
    数组的子集
    查找字符串中的最长无重复字符的子串
    双通道无限蓝屏
  • 原文地址:https://www.cnblogs.com/yangxinpython/p/12717964.html
Copyright © 2011-2022 走看看