Beetle Tracker的设计目的是用于服务器资源收集和分配的应用服务平台,通过Beetle Tracker制定不同应用服务器的状态信息收集,并可以根据应用的请求分配最适合操作的服务器资源信息.开发者可以根据自己的需求制定服务资源收集和分配规则并挂载到Beetle Tracke服务中,从而实简单的集群服务器信息收集和分配工作.
性能指标
服务设计的性能指标是单台服务器可以承载50K/秒的资源分配任务.
可扩展性能
服务通讯接口的方式来挂载应用,只需根据应用的需实现相应的规则并配置到服务中即可使用.自定义规则主要有以下接口:
信息定义
public interface IProperties { void FromHeaders(IDictionary<string, string> header); IDictionary<string, string> ToHeaders(); }实现用例public class TestProperties:Beetle.Tracker.Properties { public string Group { get { return this["GROUP"]; } set { this["GROUP"] = value; } } public string Host { get { return this["HOST"]; } set { this["HOST"] = value; } } public string Port { get { return this["PORT"]; } set { this["PORT"] = value; } } public string Node { get { return this["NODE"]; } set { this["NODE"] = value; } } }
信息序列化
实现用例public interface IInfoFormater { object FromString(Type type,string value); string ToStringValue(object obj); }public interface IAppTrackerHandler { IInfoFormater Formater { get; set; } AppHost GetHost(IProperties properties); IProperties Register(IProperties properties); TrackerInfo GetInfo(IProperties properties); }
服务器信息收集和分配
实现用例public interface IAppTrackerHandler { IInfoFormater Formater { get; set; } AppHost GetHost(IProperties properties); IProperties Register(IProperties properties); TrackerInfo GetInfo(IProperties properties); }public class TestTackerHandler :MarshalByRefObject, Beetle.Tracker.IAppTrackerHandler { public TestTackerHandler() { Formater = new TestFormater(); } private long mCursorIndex = 0; private List<Group> mGroups = new List<Group>(); public IInfoFormater Formater { get; set; } public IProperties Register(IProperties properties) { lock (mGroups) { TestProperties tp = new TestProperties(); tp.FromHeaders(properties.ToHeaders()); Group group = mGroups.Find(e => e.Name == tp.Group); if (group == null) { group = new Group(); group.Name = tp.Group; group.Nodes = new List<Node>(); group.Nodes.Add(new Node { Name = tp.Node, Host = tp.Host, Port = tp.Port, LastTrackTime=DateTime.Now }); mGroups.Add(group); } else { Node node = group.Nodes.Find(n => n.Name== tp.Node ); if(node !=null) node.LastTrackTime = DateTime.Now; else group.Nodes.Add(new Node { Name = tp.Node, Host = tp.Host, Port = tp.Port, LastTrackTime = DateTime.Now }); } return new Properties(); } } public TrackerInfo GetInfo(IProperties properties) { TrackerInfo result = new TrackerInfo(); result.TypeName = "Beetle.Tracker.TestImpl.Group,Beetle.Tracker.TestImpl"; TestProperties tp = new TestProperties(); tp.FromHeaders(properties.ToHeaders()); Group group = mGroups.Find(e => e.Name == tp.Group); if (group == null) return null; result.Data= Formater.ToStringValue(group); return result; } public override object InitializeLifetimeService() { return null; } public AppHost GetHost(IProperties properties) { int g = 0; while (g < mGroups.Count) { int i = 0; Group group = mGroups[(int)(mCursorIndex % mGroups.Count)]; mCursorIndex++; while (i < group.Nodes.Count) { Node node = group.Nodes[(int)(group.CursorIndex % group.Nodes.Count)]; group.CursorIndex++; if ((DateTime.Now - node.LastTrackTime).TotalSeconds < 5) return new AppHost { Host = node.Host, Port = int.Parse(node.Port) }; i++; } g++; } return null; } }
性能测试结果
使用一台笔记本作为服务端测试,其测试结果是当前服务可承载2.5W/每秒的服务器分配请求处理.