Пример #1
0
 private void visit()
 {
     if (Disposed)
     {
         return;
     }
     try
     {
         visitCore();
     }
     catch (Exception error)
     {
         App.Log.Write(new Log.Message
         {
             Type      = Log.MessageType.Error,
             Topic     = CoreConsts.APPLICATION_TOPIC,
             From      = "{0}.visit()".Args(GetType().Name),
             Text      = error.ToMessageWithType(),
             Exception = error
         });
     }
     finally
     {
         if (!DisposeStarted)
         {
             Task.Delay(IntUtils.ChangeByRndPct(THREAD_GRANULARITY_MS, 0.25f))
             .ContinueWith(_ => visit());
         }
     }
 }
Пример #2
0
 private void visit()
 {
     if (Disposed)
     {
         return;
     }
     try
     {
         visitCore();
     }
     catch (Exception error)
     {
         WriteLog(Log.MessageType.Error, nameof(visitCore), "Leaked: " + error.ToMessageWithType(), error);
     }
     finally
     {
         if (!Disposed)
         {
             Task.Delay(IntUtils.ChangeByRndPct(VISIT_GRANULARITY_MS, 0.25f))
             .ContinueWith(_ => visit());
         }
     }
 }
Пример #3
0
        private void trax()
        {
            __threadCount     = tbTraxThreads.Text.AsInt(1);
            __writesSec       = tbTraxWrites.Text.AsInt(0);
            __delSec          = tbTraxDeletes.Text.AsInt(0);
            __payloadVariance = tbTraxVariance.Text.AsInt(0);
            __payloadType     = rbtPerson.Checked ? ptype.Person : rbtPerson2.Checked ? ptype.Person2 : rbtString.Checked ? ptype.String : ptype.ByteArray;

            var added = 0;

            while (chkTraxer.Checked && m_Traxers.Count < __threadCount)
            {
                var context = new tcontext();
                var thread  = new Thread(
                    (ctx) =>
                {
                    try
                    {
                        var pps = new PilePointer[4000000];
                        for (var i = 0; i < pps.Length; i++)
                        {
                            pps[i] = PilePointer.Invalid;
                        }
                        var ppi = 0;
                        var di  = 0;

                        while (m_Pile.Running && !((tcontext)ctx).STOP)
                        {
                            var tc = __threadCount;
                            if (tc == 0)
                            {
                                return;
                            }

                            var wc = __writesSec / tc;
                            var dc = __delSec / tc;

                            var w = 0;
                            var d = 0;
                            while (w < wc || d < dc)
                            {
                                if (w < wc)
                                {
                                    object payload;

                                    if (__payloadType == ptype.Person)
                                    {
                                        var p = Person.MakeFake();
                                        if (__payloadVariance > 0)
                                        {
                                            p.BinData = new byte[IntUtils.ChangeByRndPct(__payloadVariance, -0.25f)];
                                        }
                                        payload = p;
                                    }
                                    else if (__payloadType == ptype.Person2)
                                    {
                                        var p = Person2.MakeFake2();
                                        if (__payloadVariance > 0)
                                        {
                                            p.BinData = new byte[IntUtils.ChangeByRndPct(__payloadVariance, -0.25f)];
                                        }
                                        payload = p;
                                    }
                                    else if (__payloadType == ptype.String)
                                    {
                                        payload = new string(' ', __payloadVariance);
                                    }
                                    else
                                    {
                                        payload = new byte[__payloadVariance];
                                    }



                                    var pp   = m_Pile.Put(payload);
                                    pps[ppi] = pp;
                                    ppi++;
                                    if (ppi == pps.Length)
                                    {
                                        ppi = 0;
                                    }
                                    w++;
                                }

                                if (d < dc)
                                {
                                    if (di == pps.Length)
                                    {
                                        di = 0;
                                    }
                                    var pp = pps[di];
                                    if (pp.Address >= 0)
                                    {
                                        m_Pile.Delete(pp);
                                        pps[di] = PilePointer.Invalid;
                                    }
                                    d++;
                                    di++;
                                }
                            }
                        }
                    }
                    catch (Exception error)//abort etc..
                    {
                        m_Errors.Enqueue(error.ToMessageWithType());
                    }
                });
                m_Traxers.Add(context);
                thread.Start(context);
                added++;
            }

            if (added > 0)
            {
                log("{0} added {1} threads".Args(DateTime.Now, added));
            }

            var removed = 0;

            while ((!chkTraxer.Checked && m_Traxers.Count > 0) || m_Traxers.Count > __threadCount)
            {
                m_Traxers[0].STOP = true;
                m_Traxers.RemoveAt(0);
                removed++;
            }

            if (removed > 0)
            {
                log("{0} removed {1} threads".Args(DateTime.Now, removed));
            }
        }