提交 13f95d8c 编写于 作者: cdy816's avatar cdy816

性能优化

上级 e7e3cd0b
...@@ -71,6 +71,16 @@ namespace Cdy.Tag.Driver ...@@ -71,6 +71,16 @@ namespace Cdy.Tag.Driver
/// <returns></returns> /// <returns></returns>
bool SetTagValue(int id, object value,DateTime time,byte quality); bool SetTagValue(int id, object value,DateTime time,byte quality);
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <param name="quality"></param>
/// <returns></returns>
bool SetTagValue(int id, object value, byte quality);
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -89,6 +99,9 @@ namespace Cdy.Tag.Driver ...@@ -89,6 +99,9 @@ namespace Cdy.Tag.Driver
/// <returns></returns> /// <returns></returns>
bool SetTagValue(Tagbase tag, object value, DateTime time, byte quality); bool SetTagValue(Tagbase tag, object value, DateTime time, byte quality);
bool SetTagValue(Tagbase tag, object value, byte quality);
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -137,7 +137,9 @@ namespace SimDriver ...@@ -137,7 +137,9 @@ namespace SimDriver
// mTickCount = 0; // mTickCount = 0;
//} //}
if((mLastProcessTime-time).TotalSeconds>1000) //LoggerService.Service.Info("Sim Driver", "Sart: " + time,ConsoleColor.DarkMagenta);
if ((mLastProcessTime-time).TotalSeconds>1000)
{ {
LoggerService.Service.Warn("Sim Driver", "出现阻塞"); LoggerService.Service.Warn("Sim Driver", "出现阻塞");
} }
...@@ -161,12 +163,13 @@ namespace SimDriver ...@@ -161,12 +163,13 @@ namespace SimDriver
double sval = Math.Sin(mNumber / 180.0 * Math.PI); double sval = Math.Sin(mNumber / 180.0 * Math.PI);
//#if DEBUG //#if DEBUG
//if(mNumber%10==0)
//Log("Sim:Sin " + fval + " " + "Sim:Cos " + sval + " " + "Sim:step " + mNumber + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
Stopwatch sw = new Stopwatch(); Stopwatch sw = new Stopwatch();
sw.Start(); sw.Start();
//if(mNumber%10==0) //#endif
Log("Sim:Sin " + fval + " " + "Sim:Cos " + sval + " " + "Sim:step " + mNumber + " " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"));
//#endif
System.Threading.Tasks.Parallel.ForEach(mTagIdCach, (vv) => System.Threading.Tasks.Parallel.ForEach(mTagIdCach, (vv) =>
...@@ -193,17 +196,14 @@ namespace SimDriver ...@@ -193,17 +196,14 @@ namespace SimDriver
} }
}); });
mTagService.SubmiteNotifyChanged(); mTagService.SubmiteNotifyChanged();
//#if DEBUG
sw.Stop(); sw.Stop();
if (mNumber % 5 == 0 && mIsSecond)
LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds);
//#endif
int delay = (int)(500 - (DateTime.Now - mLastProcessTime).TotalMilliseconds); int delay = (int)(500 - (DateTime.Now - mLastProcessTime).TotalMilliseconds);
if(delay < 0) if(delay < 0)
{ {
delay = 1; delay = 1;
} }
LoggerService.Service.Info("Sim Driver", "set value elapsed:" + sw.ElapsedMilliseconds,ConsoleColor.Yellow);
Thread.Sleep(delay); Thread.Sleep(delay);
} }
} }
......
...@@ -25,11 +25,17 @@ namespace SpiderDriver.ClientApi ...@@ -25,11 +25,17 @@ namespace SpiderDriver.ClientApi
/// </summary> /// </summary>
public const byte RealValueFun = 1; public const byte RealValueFun = 1;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
public const byte SetTagValueFun = 11; public const byte SetTagValueFun = 11;
/// <summary>
///
/// </summary>
public const byte SetTagValueAndQualityFun = 12;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -299,6 +299,88 @@ namespace SpiderDriver.ClientApi ...@@ -299,6 +299,88 @@ namespace SpiderDriver.ClientApi
} }
private void SetTagValueToBuffer(TagType type, object value,byte quality, IByteBuffer re)
{
re.WriteByte((byte)type);
switch (type)
{
case TagType.Bool:
re.WriteByte((byte)value);
break;
case TagType.Byte:
re.WriteByte((byte)value);
break;
case TagType.Short:
re.WriteShort((short)value);
break;
case TagType.UShort:
re.WriteUnsignedShort((ushort)value);
break;
case TagType.Int:
re.WriteInt((int)value);
break;
case TagType.UInt:
re.WriteInt((int)value);
break;
case TagType.Long:
case TagType.ULong:
re.WriteLong((long)value);
break;
case TagType.Float:
re.WriteFloat((float)value);
break;
case TagType.Double:
re.WriteDouble((double)value);
break;
case TagType.String:
string sval = value.ToString();
re.WriteInt(sval.Length);
re.WriteString(sval, Encoding.Unicode);
break;
case TagType.DateTime:
re.WriteLong(((DateTime)value).Ticks);
break;
case TagType.IntPoint:
re.WriteInt(((IntPointData)value).X);
re.WriteInt(((IntPointData)value).Y);
break;
case TagType.UIntPoint:
re.WriteInt((int)((UIntPointData)value).X);
re.WriteInt((int)((UIntPointData)value).Y);
break;
case TagType.IntPoint3:
re.WriteInt(((IntPoint3Data)value).X);
re.WriteInt(((IntPoint3Data)value).Y);
re.WriteInt(((IntPoint3Data)value).Z);
break;
case TagType.UIntPoint3:
re.WriteInt((int)((UIntPoint3Data)value).X);
re.WriteInt((int)((UIntPoint3Data)value).Y);
re.WriteInt((int)((UIntPoint3Data)value).Z);
break;
case TagType.LongPoint:
re.WriteLong(((LongPointData)value).X);
re.WriteLong(((LongPointData)value).Y);
break;
case TagType.ULongPoint:
re.WriteLong((long)((ULongPointData)value).X);
re.WriteLong((long)((ULongPointData)value).Y);
break;
case TagType.LongPoint3:
re.WriteLong(((LongPoint3Data)value).X);
re.WriteLong(((LongPoint3Data)value).Y);
re.WriteLong(((LongPoint3Data)value).Z);
break;
case TagType.ULongPoint3:
re.WriteLong((long)((ULongPoint3Data)value).X);
re.WriteLong((long)((ULongPoint3Data)value).Y);
re.WriteLong((long)((ULongPoint3Data)value).Z);
break;
}
re.WriteByte(quality);
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
...@@ -335,6 +417,43 @@ namespace SpiderDriver.ClientApi ...@@ -335,6 +417,43 @@ namespace SpiderDriver.ClientApi
return false; return false;
} }
/// <summary>
///
/// </summary>
/// <param name="values"></param>
/// <param name="timeout"></param>
/// <returns></returns>
public bool SetTagValue(Dictionary<int, Tuple<TagType, object,byte>> values, int timeout = 5000)
{
CheckLogin();
var mb = GetBuffer(ApiFunConst.RealValueFun, 8 + values.Count * 32);
mb.WriteByte(ApiFunConst.SetTagValueAndQualityFun);
mb.WriteLong(this.mLoginId);
mb.WriteInt(values.Count);
foreach (var vv in values)
{
mb.WriteInt(vv.Key);
SetTagValueToBuffer(vv.Value.Item1, vv.Value.Item2,vv.Value.Item3, mb);
}
realRequreEvent.Reset();
Send(mb);
try
{
if (realRequreEvent.WaitOne(timeout))
{
return mRealRequreData != null && mRealRequreData.ReadableBytes > 1;
}
}
catch
{
}
return false;
}
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -30,6 +30,11 @@ namespace SpiderDriver ...@@ -30,6 +30,11 @@ namespace SpiderDriver
/// </summary> /// </summary>
public const byte SetTagValueFun = 11; public const byte SetTagValueFun = 11;
/// <summary>
///
/// </summary>
public const byte SetTagValueAndQualityFun = 12;
/// <summary> /// <summary>
/// ///
/// </summary> /// </summary>
......
...@@ -103,6 +103,8 @@ namespace SpiderDriver ...@@ -103,6 +103,8 @@ namespace SpiderDriver
case APIConst.SetTagValueFun: case APIConst.SetTagValueFun:
ProcessSetRealData(client, data); ProcessSetRealData(client, data);
break; break;
case APIConst.SetTagValueAndQualityFun:
break;
case APIConst.RegistorTag: case APIConst.RegistorTag:
ProcessValueChangeNotify(client, data); ProcessValueChangeNotify(client, data);
break; break;
...@@ -208,7 +210,91 @@ namespace SpiderDriver ...@@ -208,7 +210,91 @@ namespace SpiderDriver
Parent.AsyncCallback(clientid, ToByteBuffer(APIConst.RealValueFun, (byte)1)); Parent.AsyncCallback(clientid, ToByteBuffer(APIConst.RealValueFun, (byte)1));
} }
private void ProcessSetRealDataAndQuality(string clientid, IByteBuffer block)
{
var service = ServiceLocator.Locator.Resolve<IRealTagProduct>();
int count = block.ReadInt();
for (int i = 0; i < count; i++)
{
var id = block.ReadInt();
byte typ = block.ReadByte();
object value = null;
switch (typ)
{
case (byte)TagType.Bool:
value = block.ReadByte();
break;
case (byte)TagType.Byte:
value = block.ReadByte();
break;
case (byte)TagType.Short:
value = block.ReadShort();
break;
case (byte)TagType.UShort:
value = (ushort)block.ReadShort();
break;
case (byte)TagType.Int:
value = block.ReadInt();
break;
case (byte)TagType.UInt:
value = (uint)block.ReadInt();
break;
case (byte)TagType.Long:
value = block.ReadLong();
break;
case (byte)TagType.ULong:
value = (ulong)block.ReadLong();
break;
case (byte)TagType.Float:
value = block.ReadFloat();
break;
case (byte)TagType.Double:
value = block.ReadDouble();
break;
case (byte)TagType.String:
value = block.ReadString();
break;
case (byte)TagType.DateTime:
var tick = block.ReadLong();
value = new DateTime(tick);
break;
case (byte)TagType.IntPoint:
value = new IntPointData(block.ReadInt(), block.ReadInt());
break;
case (byte)TagType.UIntPoint:
value = new UIntPointData(block.ReadInt(), block.ReadInt());
break;
case (byte)TagType.IntPoint3:
value = new IntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
break;
case (byte)TagType.UIntPoint3:
value = new UIntPoint3Data(block.ReadInt(), block.ReadInt(), block.ReadInt());
break;
case (byte)TagType.LongPoint:
value = new LongPointData(block.ReadLong(), block.ReadLong());
break;
case (byte)TagType.ULongPoint:
value = new ULongPointData(block.ReadLong(), block.ReadLong());
break;
case (byte)TagType.LongPoint3:
value = new LongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
break;
case (byte)TagType.ULongPoint3:
value = new ULongPoint3Data(block.ReadLong(), block.ReadLong(), block.ReadLong());
break;
}
var qua = block.ReadByte();
if (AllowTagIds.Contains(id))
service.SetTagValue(id, value,qua);
}
service.SubmiteNotifyChanged();
Parent.AsyncCallback(clientid, ToByteBuffer(APIConst.RealValueFun, (byte)1));
}
private void ProcessRemoveValueChangeNotify(string clientId, IByteBuffer block) private void ProcessRemoveValueChangeNotify(string clientId, IByteBuffer block)
{ {
......
...@@ -3211,7 +3211,7 @@ namespace Cdy.Tag ...@@ -3211,7 +3211,7 @@ namespace Cdy.Tag
{ {
Take(); Take();
var tag = mConfigDatabase.Tags[id]; var tag = mConfigDatabase.Tags[id];
SetTagValue(tag,value); SetTagValue(tag,value);
} }
catch catch
...@@ -3246,6 +3246,30 @@ namespace Cdy.Tag ...@@ -3246,6 +3246,30 @@ namespace Cdy.Tag
return true; return true;
} }
/// <summary>
///
/// </summary>
/// <param name="id"></param>
/// <param name="value"></param>
/// <param name="quality"></param>
/// <returns></returns>
public bool SetTagValue(int id, object value, byte quality)
{
return SetTagValue(id, value, DateTime.Now, quality);
}
/// <summary>
///
/// </summary>
/// <param name="tag"></param>
/// <param name="value"></param>
/// <param name="quality"></param>
/// <returns></returns>
public bool SetTagValue(Tagbase tag, object value, byte quality)
{
return SetTagValue(tag, value, DateTime.Now, quality);
}
public bool SetTagValue(Tagbase tag, object value, DateTime time, byte quality) public bool SetTagValue(Tagbase tag, object value, DateTime time, byte quality)
{ {
try try
...@@ -3371,6 +3395,8 @@ namespace Cdy.Tag ...@@ -3371,6 +3395,8 @@ namespace Cdy.Tag
{ {
try try
{ {
//if (tag.Id == 1) LoggerService.Service.Info("RealEnginer", "set tag" + tag.Id + " value: " + value,ConsoleColor.Cyan);
Take(); Take();
if (tag.ReadWriteType == ReadWriteMode.Write) return true; if (tag.ReadWriteType == ReadWriteMode.Write) return true;
DateTime time = DateTime.Now; DateTime time = DateTime.Now;
......
...@@ -43,10 +43,6 @@ ...@@ -43,10 +43,6 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="His\New\" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent"> <Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="copy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)\Output&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)$(TargetName).XML&quot; copy &quot;$(TargetDir)$(TargetName).XML&quot; &quot;$(SolutionDir)\Output\Xml&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)$(TargetName).pdb&quot; copy &quot;$(TargetDir)$(TargetName).pdb&quot; &quot;$(SolutionDir)\Output&quot; /y&#xD;&#xA;copy &quot;$(TargetDir)Config\*.cfg&quot; &quot;$(SolutionDir)\Output\Config&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)zh-CN&quot; copy &quot;$(TargetDir)zh-CN\*.dll&quot; &quot;$(SolutionDir)\Output\zh-CN&quot; /y&#xD;&#xA;" /> <Exec Command="copy &quot;$(TargetPath)&quot; &quot;$(SolutionDir)\Output&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)$(TargetName).XML&quot; copy &quot;$(TargetDir)$(TargetName).XML&quot; &quot;$(SolutionDir)\Output\Xml&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)$(TargetName).pdb&quot; copy &quot;$(TargetDir)$(TargetName).pdb&quot; &quot;$(SolutionDir)\Output&quot; /y&#xD;&#xA;copy &quot;$(TargetDir)Config\*.cfg&quot; &quot;$(SolutionDir)\Output\Config&quot; /y&#xD;&#xA;if exist &quot;$(TargetDir)zh-CN&quot; copy &quot;$(TargetDir)zh-CN\*.dll&quot; &quot;$(SolutionDir)\Output\zh-CN&quot; /y&#xD;&#xA;" />
</Target> </Target>
......
...@@ -34,6 +34,9 @@ namespace Cdy.Tag ...@@ -34,6 +34,9 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private Cdy.Tag.RealEnginer mRealEnginer; private Cdy.Tag.RealEnginer mRealEnginer;
/// <summary>
///
/// </summary>
private LogManager2 mLogManager; private LogManager2 mLogManager;
/// <summary> /// <summary>
...@@ -87,7 +90,9 @@ namespace Cdy.Tag ...@@ -87,7 +90,9 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private HisDataMemoryBlockCollection mCurrentMergeMemory; private HisDataMemoryBlockCollection mCurrentMergeMemory;
/// <summary>
///
/// </summary>
private HisDataMemoryBlockCollection mWaitForMergeMemory; private HisDataMemoryBlockCollection mWaitForMergeMemory;
/// <summary> /// <summary>
...@@ -213,12 +218,24 @@ namespace Cdy.Tag ...@@ -213,12 +218,24 @@ namespace Cdy.Tag
#region ... Methods ... #region ... Methods ...
/// <summary>
///
/// </summary>
/// <param name="totalTagCount"></param>
private void UpdatePerProcesserMaxTagCount(int totalTagCount)
{
int count = Environment.ProcessorCount / 2;
int pcount = totalTagCount / count + count;
TimerMemoryCacheProcesser2.MaxTagCount = ValueChangedMemoryCacheProcesser2.MaxTagCount = pcount;
}
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
public void Init() public void Init()
{ {
Stopwatch sw = new Stopwatch();
sw.Start();
if (mRealEnginer != null) if (mRealEnginer != null)
{ {
//if (mManager == null) //if (mManager == null)
...@@ -231,6 +248,8 @@ namespace Cdy.Tag ...@@ -231,6 +248,8 @@ namespace Cdy.Tag
mValueChangedProcesser.Clear(); mValueChangedProcesser.Clear();
mValueChangedProcesser.Add(mLastValueChangedProcesser); mValueChangedProcesser.Add(mLastValueChangedProcesser);
UpdatePerProcesserMaxTagCount(mManager.HisTags.Count);
var count = CachMemoryTime; var count = CachMemoryTime;
var realbaseaddr = mRealEnginer.Memory; var realbaseaddr = mRealEnginer.Memory;
IntPtr realHandle = mRealEnginer.MemoryHandle; IntPtr realHandle = mRealEnginer.MemoryHandle;
...@@ -312,7 +331,10 @@ namespace Cdy.Tag ...@@ -312,7 +331,10 @@ namespace Cdy.Tag
mTagCount++; mTagCount++;
} }
} }
long ltmp = sw.ElapsedMilliseconds;
AllocMemory(); AllocMemory();
sw.Stop();
LoggerService.Service.Info("HisEnginer", "生成对象耗时:"+ltmp+" 内存分配耗时:"+(sw.ElapsedMilliseconds-ltmp));
} }
/// <summary> /// <summary>
...@@ -338,6 +360,8 @@ namespace Cdy.Tag ...@@ -338,6 +360,8 @@ namespace Cdy.Tag
/// <param name="mHisDatabase"></param> /// <param name="mHisDatabase"></param>
public void ReLoadTags(IEnumerable<Tag.HisTag> tags,HisDatabase mHisDatabase) public void ReLoadTags(IEnumerable<Tag.HisTag> tags,HisDatabase mHisDatabase)
{ {
UpdatePerProcesserMaxTagCount(mManager.HisTags.Count+tags.Count());
mRecordTimer.Stop(); mRecordTimer.Stop();
var realbaseaddr = this.mRealEnginer.Memory; var realbaseaddr = this.mRealEnginer.Memory;
IntPtr realHandle = mRealEnginer.MemoryHandle; IntPtr realHandle = mRealEnginer.MemoryHandle;
...@@ -347,6 +371,9 @@ namespace Cdy.Tag ...@@ -347,6 +371,9 @@ namespace Cdy.Tag
var histags = new List<HisRunTag>(); var histags = new List<HisRunTag>();
int tcount = 0;
int vcount = 0;
foreach (var vv in tags) foreach (var vv in tags)
{ {
var realaddr = (int)mRealEnginer.GetDataAddr((int)vv.Id); var realaddr = (int)mRealEnginer.GetDataAddr((int)vv.Id);
...@@ -403,20 +430,13 @@ namespace Cdy.Tag ...@@ -403,20 +430,13 @@ namespace Cdy.Tag
if (mHisTag.Type == Cdy.Tag.RecordType.Timer) if (mHisTag.Type == Cdy.Tag.RecordType.Timer)
{ {
if (!mLastProcesser.AddTag(mHisTag)) mRecordTimerProcesser[tcount++].AddTag(mHisTag);
{ tcount = tcount >= mRecordTimerProcesser.Count ? 0 : tcount;
mLastProcesser = new TimerMemoryCacheProcesser2() { Id = mLastProcesser.Id + 1 };
mLastProcesser.AddTag(mHisTag);
mRecordTimerProcesser.Add(mLastProcesser);
}
} }
else else
{ {
if (!mLastValueChangedProcesser.AddTag(mHisTag)) mValueChangedProcesser[vcount++].AddTag(mHisTag);
{ vcount = vcount >= mRecordTimerProcesser.Count ? 0 : vcount;
mLastValueChangedProcesser = new ValueChangedMemoryCacheProcesser2() { Name = "ValueChanged" + mTagCount };
mValueChangedProcesser.Add(mLastValueChangedProcesser);
}
} }
mTagCount++; mTagCount++;
} }
...@@ -454,9 +474,9 @@ namespace Cdy.Tag ...@@ -454,9 +474,9 @@ namespace Cdy.Tag
this.mManager = mHisDatabase; this.mManager = mHisDatabase;
foreach (var vv in mRecordTimerProcesser) { if (!vv.IsStarted) vv.Start(); } //foreach (var vv in mRecordTimerProcesser) { if (!vv.IsStarted) vv.Start(); }
foreach (var vv in mValueChangedProcesser) { if (!vv.IsStarted) vv.Start(); } //foreach (var vv in mValueChangedProcesser) { if (!vv.IsStarted) vv.Start(); }
mLogManager.InitHeadData(); mLogManager.InitHeadData();
...@@ -1052,17 +1072,14 @@ namespace Cdy.Tag ...@@ -1052,17 +1072,14 @@ namespace Cdy.Tag
var mm = dt.Minute; var mm = dt.Minute;
if (mm!=mLastProcessTick ) if (mm!=mLastProcessTick )
{ {
///处理第一次运行的情况,轻质到一秒的开始部分 ///处理第一次运行的情况,停止到一秒的开始部分
if (mLastProcessTick == -1 && dt.Millisecond > 400) if (mLastProcessTick == -1 && dt.Millisecond > 400)
{ {
mIsBusy = false; mIsBusy = false;
return; return;
} }
LoggerService.Service.Info("Record", mm+"!="+mLastProcessTick+ "-------------------------------------------------------------------------", ConsoleColor.Green); LoggerService.Service.Info("Record", "准备新的内存,提交内存 "+ CurrentMemory.Name+ " 到压缩 线程ID:"+ Thread.CurrentThread.ManagedThreadId+" CPU ID:"+ ThreadHelper.GetCurrentProcessorNumber(), ConsoleColor.Green);
LoggerService.Service.Info("Record", "准备新的内存,提交内存 "+ CurrentMemory.Name+ " 到压缩");
//Stopwatch sw = new Stopwatch();
//sw.Start();
if (mLastProcessTick != -1) if (mLastProcessTick != -1)
{ {
mLastProcessTime = dt; mLastProcessTime = dt;
...@@ -1071,9 +1088,6 @@ namespace Cdy.Tag ...@@ -1071,9 +1088,6 @@ namespace Cdy.Tag
SubmiteMemory(dt); SubmiteMemory(dt);
} }
mLastProcessTick = mm; mLastProcessTick = mm;
//sw.Stop();
// LoggerService.Service.Info("Record", (CurrentMemory!=null? CurrentMemory.Name:"")+" 内存初始化:" + sw.ElapsedMilliseconds);
LoggerService.Service.Info("Record", "*************************************************************************", ConsoleColor.Green);
} }
foreach (var vv in mRecordTimerProcesser) foreach (var vv in mRecordTimerProcesser)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
//============================================================== //==============================================================
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text; using System.Text;
namespace Cdy.Tag namespace Cdy.Tag
...@@ -21,5 +22,36 @@ namespace Cdy.Tag ...@@ -21,5 +22,36 @@ namespace Cdy.Tag
/// ///
/// </summary> /// </summary>
public override byte SizeOfValue => 8; public override byte SizeOfValue => 8;
//private double mLastValue = -1;
//private DateTime mHisTime;
///// <summary>
/////
///// </summary>
///// <param name="count"></param>
///// <param name="tim"></param>
//public unsafe override void UpdateValue2(int count, int tim)
//{
// base.UpdateValue2(count, tim);
// if (this.Id == 1)
// {
// double dtmp = MemoryHelper.ReadDouble((void*)(RealMemoryPtr), RealValueAddr);
// var mQuality = RealMemoryAddr[RealValueAddr + SizeOfValue + 8];
// if (mLastValue != dtmp)
// {
// mLastValue = dtmp;
// LoggerService.Service.Info("DoubleHisTag", mLastValue + "last time:" + mHisTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), ConsoleColor.Green);
// }
// else
// {
// var dt = DateTime.Now;
// LoggerService.Service.Info("DoubleHisTag", dtmp + " = " + mLastValue + "last time:" + mHisTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), ConsoleColor.Red);
// }
// mHisTime = DateTime.Now;
// }
//}
} }
} }
...@@ -182,23 +182,18 @@ namespace Cdy.Tag ...@@ -182,23 +182,18 @@ namespace Cdy.Tag
[Obsolete] [Obsolete]
public void UpdateValue(int count,int tim) public void UpdateValue(int count,int tim)
{ {
//lock (mLockTest) var vcount = count > MaxCount ? MaxCount : count;
//{ Count = vcount;
var vcount = count > MaxCount ? MaxCount : count;
Count = vcount;
//数据内容: 时间戳(time1+time2+...) +数值区(value1+value2+...)+质量戳区(q1+q2+....) //数据内容: 时间戳(time1+time2+...) +数值区(value1+value2+...)+质量戳区(q1+q2+....)
//实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节 //实时数据内存结构为:实时值+时间戳+质量戳,时间戳2个字节,质量戳1个字节
HisAddr.WriteUShortDirect(TimerValueStartAddr + vcount * 2, (ushort)(tim)); HisAddr.WriteUShortDirect(TimerValueStartAddr + vcount * 2, (ushort)(tim));
//写入数值 //写入数值
//HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryAddr, RealValueAddr, SizeOfValue); HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryPtr, RealValueAddr, SizeOfValue);
//LoggerService.Service.Erro("HisTag","read from realmemory:"+ MemoryHelper.ReadDouble((void*)RealMemoryPtr, RealValueAddr));
HisAddr.WriteBytesDirect(HisValueStartAddr + vcount * SizeOfValue, RealMemoryPtr, RealValueAddr, SizeOfValue);
//更新质量戳 //更新质量戳
HisAddr.WriteByteDirect(HisQulityStartAddr + vcount, RealMemoryAddr[RealValueAddr + SizeOfValue + 8]); HisAddr.WriteByteDirect(HisQulityStartAddr + vcount, RealMemoryAddr[RealValueAddr + SizeOfValue + 8]);
//}
} }
/// <summary> /// <summary>
...@@ -216,7 +211,7 @@ namespace Cdy.Tag ...@@ -216,7 +211,7 @@ namespace Cdy.Tag
/// </summary> /// </summary>
/// <param name="count"></param> /// <param name="count"></param>
/// <param name="tim"></param> /// <param name="tim"></param>
public void UpdateValue2(int count, int tim) public virtual void UpdateValue2(int count, int tim)
{ {
var vcount = count > MaxCount ? MaxCount : count; var vcount = count > MaxCount ? MaxCount : count;
Count = vcount; Count = vcount;
...@@ -226,8 +221,6 @@ namespace Cdy.Tag ...@@ -226,8 +221,6 @@ namespace Cdy.Tag
HisValueMemoryStartAddr.WriteUShortDirect((int)(HisValueMemoryStartAddr.TimerAddress + vcount * 2), (ushort)(tim)); HisValueMemoryStartAddr.WriteUShortDirect((int)(HisValueMemoryStartAddr.TimerAddress + vcount * 2), (ushort)(tim));
//写入数值 //写入数值
// Array.Copy(RealMemoryAddr, RealValueAddr, HisValueMemoryStartAddr.Buffers, (int)(HisValueMemoryStartAddr.ValueAddress + vcount * SizeOfValue), SizeOfValue);
HisValueMemoryStartAddr.WriteBytesDirect((int)(HisValueMemoryStartAddr.ValueAddress + vcount * SizeOfValue), RealMemoryPtr, RealValueAddr, SizeOfValue); HisValueMemoryStartAddr.WriteBytesDirect((int)(HisValueMemoryStartAddr.ValueAddress + vcount * SizeOfValue), RealMemoryPtr, RealValueAddr, SizeOfValue);
//更新质量戳 //更新质量戳
......
...@@ -34,7 +34,7 @@ namespace Cdy.Tag ...@@ -34,7 +34,7 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private Dictionary<long, long> mCount = new Dictionary<long, long>(); private Dictionary<long, long> mCount = new Dictionary<long, long>();
public const int MaxTagCount = 100000; public static int MaxTagCount = 100000;
private int mCurrentCount = 0; private int mCurrentCount = 0;
...@@ -182,18 +182,18 @@ namespace Cdy.Tag ...@@ -182,18 +182,18 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private void ThreadProcess() private void ThreadProcess()
{ {
ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray1); ThreadHelper.AssignToCPU(CPUAssignHelper.Helper.CPUArray1);
closedEvent.Reset(); closedEvent.Reset();
var vkeys = mCount.Keys.ToArray(); var vkeys = mCount.Keys.ToArray();
int ctmp = 0;
while (!mIsClosed) while (!mIsClosed)
{ {
resetEvent.WaitOne(); resetEvent.WaitOne();
resetEvent.Reset(); resetEvent.Reset();
if (mIsClosed) break; if (mIsClosed) break;
Stopwatch sw = new Stopwatch();
// LoggerService.Service.Info("TimerMemoryCacheProcesser", ThreadHelper.GetCurrentProcessorNumber() + " CPU in running!"); sw.Start();
try try
{ {
mIsBusy = true; mIsBusy = true;
...@@ -213,6 +213,13 @@ namespace Cdy.Tag ...@@ -213,6 +213,13 @@ namespace Cdy.Tag
catch catch
{ {
}
sw.Stop();
ctmp++;
if (ctmp >10 && Id==0 &&sw.ElapsedMilliseconds>0)
{
ctmp = 0;
LoggerService.Service.Info("TimerMemoryCacheProcesser", this.Id + " CPU Id" + ThreadHelper.GetCurrentProcessorNumber() + " record tag value:" + sw.ElapsedMilliseconds + " tag count:" + mCurrentCount);
} }
resetEvent.Reset(); resetEvent.Reset();
} }
...@@ -223,11 +230,12 @@ namespace Cdy.Tag ...@@ -223,11 +230,12 @@ namespace Cdy.Tag
/// <summary> /// <summary>
/// 记录一组 /// 记录一组变量
/// </summary> /// </summary>
/// <param name="tags"></param> /// <param name="tags"></param>
private void ProcessTags(List<HisRunTag> tags) private void ProcessTags(List<HisRunTag> tags)
{ int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick); {
int tim = (int)((mLastUpdateTime - HisRunTag.StartTime).TotalMilliseconds / HisEnginer.MemoryTimeTick);
foreach (var vv in tags) foreach (var vv in tags)
{ {
vv.UpdateValue2(tim); vv.UpdateValue2(tim);
......
...@@ -36,7 +36,7 @@ namespace Cdy.Tag ...@@ -36,7 +36,7 @@ namespace Cdy.Tag
/// </summary> /// </summary>
private ConcurrentDictionary<int, bool> mChangedTags = new ConcurrentDictionary<int, bool>(); private ConcurrentDictionary<int, bool> mChangedTags = new ConcurrentDictionary<int, bool>();
public const int MaxTagCount = 100000; public static int MaxTagCount = 100000;
private int mCurrentCount = 0; private int mCurrentCount = 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册