mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 增加 UseSlaveWeight 读权重设置;#1046
This commit is contained in:
@ -582,7 +582,20 @@ namespace FreeSql.Internal.CommonProvider
|
||||
if (availables.Any())
|
||||
{
|
||||
isSlave = true;
|
||||
pool = availables.Count == 1 ? availables[0] : availables[slaveRandom.Next(availables.Count)];
|
||||
if (availables.Count == 1) pool = availables[0];
|
||||
else
|
||||
{
|
||||
var rnd = slaveRandom.Next(availables.Sum(a => a.Policy.Weight));
|
||||
for(var a = 0; a < availables.Count; a++)
|
||||
{
|
||||
rnd -= availables[a].Policy.Weight;
|
||||
if (rnd < 0)
|
||||
{
|
||||
pool = availables[a];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||
public bool IsAutoDisposeWithSystem { get; set; } = true;
|
||||
public int CheckAvailableInterval { get; set; } = 5;
|
||||
public int Weight { get; set; } = 1;
|
||||
|
||||
public DbConnection OnCreate()
|
||||
{
|
||||
|
@ -17,6 +17,7 @@ namespace FreeSql.Internal.ObjectPool
|
||||
public bool IsThrowGetTimeoutException { get; set; } = true;
|
||||
public bool IsAutoDisposeWithSystem { get; set; } = true;
|
||||
public int CheckAvailableInterval { get; set; } = 5;
|
||||
public int Weight { get; set; } = 1;
|
||||
|
||||
public Func<T> CreateObject;
|
||||
public Action<Object<T>> OnGetObject;
|
||||
|
@ -48,6 +48,11 @@ namespace FreeSql.Internal.ObjectPool
|
||||
/// </summary>
|
||||
int CheckAvailableInterval { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 权重
|
||||
/// </summary>
|
||||
int Weight { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 对象池的对象被创建时
|
||||
/// </summary>
|
||||
|
Reference in New Issue
Block a user