ntminer 5 years ago
parent
commit
82bfe1e2dc

+ 0 - 23
src/AppModels/MinerStudio/Vms/GpuNameCountViewModel.cs

@@ -90,28 +90,5 @@ namespace NTMiner.MinerStudio.Vms {
                 return GpuName.ConvertToGb(this.TotalMemory) + " G";
             }
         }
-
-        public bool IsValid() {
-            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
-        }
-
-        public override bool Equals(object obj) {
-            if (obj == null) {
-                return false;
-            }
-            return this.ToString() == obj.ToString(); ;
-        }
-
-        public override int GetHashCode() {
-            return this.ToString().GetHashCode();
-        }
-
-        /// <summary>
-        /// 该ToString字符串会被作为redis key使用
-        /// </summary>
-        /// <returns></returns>
-        public override string ToString() {
-            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
-        }
     }
 }

+ 0 - 19
src/AppModels/Vms/GpuNameViewModel.cs

@@ -46,24 +46,5 @@ namespace NTMiner.Vms {
         public bool IsValid() {
             return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
         }
-
-        public override bool Equals(object obj) {
-            if (obj == null) {
-                return false;
-            }
-            return this.ToString() == obj.ToString(); ;
-        }
-
-        public override int GetHashCode() {
-            return this.ToString().GetHashCode();
-        }
-
-        /// <summary>
-        /// 该ToString字符串会被作为redis key使用
-        /// </summary>
-        /// <returns></returns>
-        public override string ToString() {
-            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
-        }
     }
 }

+ 0 - 23
src/NTMinerDataSchemas/Core/Gpus/GpuNameCount.cs

@@ -15,28 +15,5 @@
         public ulong TotalMemory { get; set; }
 
         public int Count { get; set; }
-
-        public bool IsValid() {
-            return GpuName.IsValid(this.GpuType, this.Name, this.TotalMemory);
-        }
-
-        public override bool Equals(object obj) {
-            if (obj == null) {
-                return false;
-            }
-            return this.ToString() == obj.ToString(); ;
-        }
-
-        public override int GetHashCode() {
-            return this.ToString().GetHashCode();
-        }
-
-        /// <summary>
-        /// 该ToString字符串会被作为redis key使用
-        /// </summary>
-        /// <returns></returns>
-        public override string ToString() {
-            return GpuName.Format(this.GpuType, this.Name, this.TotalMemory);
-        }
     }
 }

+ 7 - 1
src/NTMinerDataSchemas/Core/Gpus/IGpuNameCount.cs

@@ -1,5 +1,11 @@
 namespace NTMiner.Core.Gpus {
-    public interface IGpuNameCount : IGpuName {
+    public interface IGpuNameCount {
+        GpuType GpuType { get; }
+        string Name { get; }
+        /// <summary>
+        /// 单位Byte
+        /// </summary>
+        ulong TotalMemory { get; set; }
         int Count { get; }
     }
 }

+ 0 - 3
src/WebApiServer/Core/Impl/ClientDataSet.cs

@@ -129,9 +129,6 @@ namespace NTMiner.Core.Impl {
             if (!isFromWsServerNode) {
                 _speedDataRedis.SetAsync(new SpeedData(speedDto, DateTime.Now));
             }
-            foreach (var gpuSpeedData in speedDto.GpuTable) {
-                WebApiRoot.GpuNameSet.AddCount(speedDto.GpuType, gpuSpeedData.Name, gpuSpeedData.TotalMemory);
-            }
             ClientData clientData = GetByClientId(speedDto.ClientId);
             if (clientData == null) {
                 clientData = ClientData.Create(speedDto, minerIp);

+ 43 - 25
src/WebApiServer/Core/Impl/GpuNameSet.cs

@@ -1,26 +1,56 @@
 using NTMiner.Core.Gpus;
 using NTMiner.Core.Redis;
-using System;
 using System.Collections.Generic;
 
 namespace NTMiner.Core.Impl {
     public class GpuNameSet : IGpuNameSet {
-        private readonly Dictionary<string, GpuNameCount> _dic = new Dictionary<string, GpuNameCount>(StringComparer.OrdinalIgnoreCase);
+        private readonly Dictionary<GpuName, int> _gpuNameCountDic = new Dictionary<GpuName, int>();
+        // 该集合由人工维护,这里的GpuName是由人脑提取的显卡的特征名,能覆盖每一张显卡当出现未覆盖的显卡事件时会有人工即时补漏
         private readonly HashSet<GpuName> _gpuNameSet = new HashSet<GpuName>();
 
         private readonly IGpuNameRedis _gpuNameRedis;
         public GpuNameSet(IGpuNameRedis gpuNameRedis) {
             _gpuNameRedis = gpuNameRedis;
+            VirtualRoot.AddEventPath<ClientSetInitedEvent>("矿机列表初始化后计算显卡名称集合", LogEnum.DevConsole, action: message => {
+                Init();
+            }, this.GetType());
+            VirtualRoot.AddEventPath<Per10MinuteEvent>("周期刷新显卡名称集合", LogEnum.DevConsole, action: message => {
+                Init();
+            }, this.GetType());
+        }
+
+        private void Init() {
+            _gpuNameCountDic.Clear();
+            foreach (var clientData in WebApiRoot.ClientDataSet.AsEnumerable()) {
+                foreach (var gpuSpeedData in clientData.GpuTable) {
+                    AddCount(clientData.GpuType, gpuSpeedData.Name, gpuSpeedData.TotalMemory);
+                }
+            }
+        }
+
+        public void AddCount(GpuType gpuType, string gpuName, ulong gpuTotalMemory) {
+            if (gpuType == GpuType.Empty || string.IsNullOrEmpty(gpuName) || !GpuName.IsValidTotalMemory(gpuTotalMemory)) {
+                return;
+            }
+            GpuName key = new GpuName {
+                TotalMemory = gpuTotalMemory,
+                Name = gpuName,
+                GpuType = gpuType
+            };
+            if (_gpuNameCountDic.TryGetValue(key, out int count)) {
+                _gpuNameCountDic[key] = count + 1;
+            }
+            else {
+                _gpuNameCountDic.Add(key, 1);
+            }
         }
 
         public void Set(GpuName gpuName) {
             if (gpuName == null || !gpuName.IsValid()) {
                 return;
             }
-            bool isNew = _gpuNameSet.Add(gpuName);
-            if (isNew) {
-                _gpuNameRedis.SetAsync(gpuName);
-            }
+            _gpuNameSet.Add(gpuName);
+            _gpuNameRedis.SetAsync(gpuName);
         }
 
         public void Remove(GpuName gpuName) {
@@ -31,29 +61,17 @@ namespace NTMiner.Core.Impl {
             _gpuNameRedis.DeleteAsync(gpuName);
         }
 
-        public void AddCount(GpuType gpuType, string gpuName, ulong gpuTotalMemory) {
-            if (gpuType == GpuType.Empty || string.IsNullOrEmpty(gpuName) || !GpuName.IsValidTotalMemory(gpuTotalMemory)) {
-                return;
-            }
-            string key = GpuName.Format(gpuType, gpuName, gpuTotalMemory);
-            if (_dic.TryGetValue(key, out GpuNameCount gpuNameCount)) {
-                gpuNameCount.Count++;
-            }
-            else {
-                gpuNameCount = new GpuNameCount {
-                    TotalMemory = gpuTotalMemory,
-                    Name = gpuName,
-                    GpuType = gpuType,
-                    Count = 1
+        public IEnumerable<GpuNameCount> GetGpuNameCounts() {
+            foreach (var item in _gpuNameCountDic) {
+                yield return new GpuNameCount {
+                    Count = item.Value,
+                    GpuType = item.Key.GpuType,
+                    Name = item.Key.Name,
+                    TotalMemory = item.Key.TotalMemory
                 };
-                _dic.Add(key, gpuNameCount);
             }
         }
 
-        public IEnumerable<GpuNameCount> GetGpuNameCounts() {
-            return _dic.Values;
-        }
-
         public IEnumerable<GpuName> AsEnumerable() {
             return _gpuNameSet;
         }