大内存问题 [英] problem with Large Memory

查看:75
本文介绍了大内存问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,所有
我需要尽快处理大量实时数据.

此数据来自网络连接上的多个线程.

所有网络线程将数据传递给共享函数,以进行一些翻译和解释,然后将信息逐个对象保存到并发字典中.

问题是此字典中存储的对象数量达到了150K.

发生的情况是,在获取要更新的对象时,它花费的时间比接受的时间长.

Hi,all
I''ve a large amount of real time data need to be proceed as fast as possible.

This data is coming from multiple threads over network connections.

All network threads pass the data to a shared function to process it with some translation and interpretation, after that it saves the information into Concurrent Dictionary object by object.

The problem is I have an amount of objects that reaches 150K stored in this dictionary.

What happens is while fetching the object to update, it takes a long time rather than the accepted time.

public class MyObject
{  
  System.Timers.Timer LostTimer = new System.Timers.Timer();
  public int ID;
  public DateTime UpdateTime;

  public  MyObject()
  {
    LostTimer.Interval = 20000;
    LostTimer.Elapsed+=TimerElapsedHandler(LostTimer_Elapsed);
    LostTimer.Enabled = true;
  }
 
  void LostTimer_Elapsed(object sender,EventArgs e)
  {
    if(UpdateTime > DateTime.Now.AddSeconds(-20))
         Console.WriteLine(ID + " Lost...");
  }
  
}

public class MyClass
{
  public MyClass(){}

  private ConcurrentDictionary<int,MyObject> Objects = new ConcurrentDictionary<int,MyObject>();

  void NetworkThread1DataRecived(eventArgs e)
  {
    Translate(e.Data);
  }
  void Translate(string[] data)
  {
   Task.Factory.StartNew(()=>
   {
      Parallel.ForEach<string>(data, s (()=>
      {
         MyObject o = null;
         Objects.TryGet(int.Parse(s),out o)
         if(o == null)
         {       
             o = new MyObject();
             o.ID = int.Parse(s);
             o.UpdateTime = DateTime.Now;
         
             Objects.TryAdd(s,o);
         }
         else
         {
            o.UpdateTime = DateTime.Now;
         }
      });
   });
 }
}



现在,当处理超过30K的对象时,它使我丢失了对象.
请我紧急需要帮助.

谢谢!



Now when working with more than 30K of objects it gives me objects lost.
Please I need help urgently.

Thank you!

推荐答案

塔姆,

我发现你出了什么问题:

UpdateTime > DateTime.Now.AddSeconds(-20000)

将timer.Interval设置为20000ms,即20秒,但此时要减去20000秒.我认为应该只有20秒.

顺便说一句,当上面的代码片段为真时,您遵循的逻辑是什么
该对象是丢失".你能解释一下吗?

干杯

曼弗雷德(Manfred)
Hi Tamer,

I found you what''s wrong:

UpdateTime > DateTime.Now.AddSeconds(-20000)

The timer.Interval is set to 20000ms that is 20 seconds, but then you''re subtracting 20000 second. I think that should only be 20 secs.

BTW, what logic are you following that when the above snippet is true
that the object is "Lost". Can you please explain?

Cheers

Manfred


这篇关于大内存问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆