集羣服務器信息收集和分配服務Beetle.Tracker

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;
              
        }
    }


性能測試結果

20140112145227_2968.jpg

使用一臺筆記本作爲服務端測試,其測試結果是當前服務可承載2.5W/每秒的服務器分配請求處理.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章