Click here to Skip to main content
11,490,003 members (59,411 online)
Click here to Skip to main content
Add your own
alternative version

The Super Pool Framework

, 31 Aug 2010 CPOL 51.2K 1.2K 168
The Super Pool is a framework for decoupled communication and management of components. The Super Pool introduces a natural asynchronous communication environment into your solution that can be fluently spread over different components, threads, processes, or even computers or networks.
Matrix_SuperPool_Standalone.zip
Lib
PowerCollections.dll
Matrix.Framework.SuperPool.Standalone
bin
Debug
Release
Common.Sockets
Common
Core
Matrix.Common.Core
Collections
Identification
Results
Serialization
Matrix.Common.Extended
FastSerialization
Operationals
ThreadPools
Matrix.Common.Sockets
Common
Core
Matrix.Framework.MessageBus
Client
Clients
ExecutionStrategies
Core
Net
Messages
Matrix.Framework.SuperPool
Call
Clients
Core
DynamicProxy
Subscription
Matrix.Framework.SuperPool.Standalone.csproj.user
Properties
Tests
Lib
log4net.dll
Matrix.Common.Core.dll
Matrix.Common.Diagnostics.dll
Matrix.Common.Diagnostics.FrontEnd.dll
Matrix.Common.Extended.dll
Matrix.Common.FrontEnd.dll
Matrix.Common.Sockets.dll
Matrix.Framework.TestFramework.dll
nunit.framework.dll
Matrix.Framework.SuperPool.Demonstration
bin
Debug
Release
FormServer.cs.bak
Properties
Matrix.Framework.SuperPool.Test
bin
Debug
Release
Matrix.Framework.SuperPool.Test.vshost.exe.manifest
MultiThreadTests
Properties
Settings.settings
SpeedTests
Matrix.Framework.SuperPool.UnitTest
bin
Debug
Release
Matrix.Framework.SuperPool.UnitTest.csproj.user
Properties
// -----
// Copyright 2010 Deyan Timnev
// This file is part of the Matrix Platform (www.matrixplatform.com).
// The Matrix Platform is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, 
// either version 3 of the License, or (at your option) any later version. The Matrix Platform is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; 
// without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License along with the Matrix Platform. If not, see http://www.gnu.org/licenses/lgpl.html
// -----
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Matrix.Common.Diagnostics;
using Matrix.Framework.TestFramework;
using Matrix.Framework.SuperPool.Clients;
using Matrix.Framework.SuperPool.Core;

namespace Matrix.Framework.SuperPool.Test.SpeedTests
{
    /// <summary>
    /// Test the speed of super pool calls.
    /// Current config gives around 240K in Debug and 480K in Release, with call context enabled.
    /// </summary>
    public class PoolSpeedTest : SpeedTest, Interface1
    {
        Matrix.Framework.SuperPool.Core.SuperPool pool;
        SuperPoolClient client1;
        SuperPoolClient client2;

        bool _testEventHandling = true;
        /// <summary>
        /// 
        /// </summary>
        public bool TestEventHandling
        {
            get { return _testEventHandling; }
            set { _testEventHandling = value; }
        }

        public bool ContextDataEnabled
        {
            get
            {
                return SuperPoolInvocation.CallContextEnabled;
            }

            set
            {
                SuperPoolInvocation.CallContextEnabled = value;
            }
        }

        public event EventHandler Event1;

        /// <summary>
        /// Constructor.
        /// </summary>
        public PoolSpeedTest()
            : base(true)
        {
            pool = new Matrix.Framework.SuperPool.Core.SuperPool();

            client1 = new SuperPoolClient("c1", this);
            client2 = new SuperPoolClient("c2", this);

            bool result = pool.AddClient(client1);
            result = pool.AddClient(client2);
        }

        public override void Update(FormTesting form)
        {
            
        }

        public override bool OnRun(FormTesting form, int count)
        {
            if (_testEventHandling)
            {
                client1.SubscribeAll<Interface1>().Event1 += new EventHandler(SuperPoolSpeedTest_Event1);
                //client1.Subscribe<Interface1>().Event1 -= new EventHandler(SuperPoolSpeedTest_Event1);
            }

            SystemMonitor.Info("Start...");

            if (Event1 != null)
            {
                Event1(this, EventArgs.Empty);
            }

            client1.Call<Interface1>(client1.Id).Prop1 = 73;

            for (int i = 0; i < count; i++)
            {
                //AA x = pool.Call<Interface1>(client1.Id).Run(2);
                //string res = pool.Call<Interface1>(client1.Id).Run(string.Empty);
                client1.Call<Interface1>(client1.Id).Run3();
                //int xa = client2.Call<Interface1>().Prop1;

                //int result = client1.CallSync<Interface1>(client1.Id, TimeSpan.FromSeconds(2)).Run2();
                //if (result != i)
                //{
                //    int h = 11;
                //}
                //x = pool.Call<Interface1>(6).Run(2);
            }

            if (_testEventHandling)
            {
                client1.SubscribeAll<Interface1>().Event1 -= new EventHandler(SuperPoolSpeedTest_Event1);
            }

            //pool._builder.Save();
            return true;
        }

        void SuperPoolSpeedTest_Event1(object sender, EventArgs e)
        {
            int h = 2;
        }

        #region Interface1 Members

        public AA Run(int x)
        {
            throw new NotImplementedException();
        }

        public string Run(string a)
        {
            Interlocked.Increment(ref _executed);
            if (_executed >= Count)
            {
                SignalTestComplete();
            }
            return a;
        }

        public int Run2()
        {
            return IncrementExecuted() - 1;
        }

        public void Run3()
        {
            IncrementExecuted();
            //Interlocked.Increment(ref _executed);
            //if (_executed >= Count)
            //{
            //    SignalTestComplete();
            //}
        }

        #endregion


        #region Interface1 Members


        public event MyDelegate MyEvent;

        #endregion

        #region Interface1 Members

        int _prop1 = 0;
        public int Prop1
        {
            get
            {
                IncrementExecuted();
                return _prop1;
            }

            set
            {
                _prop1 = value;
            }
        }

        int _propGet = 0;
        public int PropGet
        {
            get
            {
                IncrementExecuted();
                return _propGet;
            }

            set
            {
                _propGet = value;
            }
        }

        int _propSet = 0;
        public int PropSet
        {
            set { _propSet = value; }
        }

        #endregion
    }

    public struct AA
    {
    }

    public delegate int MyDelegate(object state, double t);

    [SuperPoolInterface]
    public interface Interface1
    {
        int Prop1 { get; set; }
        int PropGet { get; set; }
        int PropSet { set; }

        AA Run(int x);
        string Run(string a);

        int Run2();
        void Run3();

        event EventHandler Event1;
        event MyDelegate MyEvent;
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Deyan Timnev
Product Manager Ingenious Ltd, Bulgaria
Bulgaria Bulgaria
I worked for a few years as a C++/Win32 developer and software architect, and then moved on to the .NET environment where I was able to discover the beauty of managed programming.

I am currently involved in the development and management of Open Forex Platform (www.openforexplatform.com) and the Matrix Platform (www.matrixplatform.com).

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 31 Aug 2010
Article Copyright 2010 by Deyan Timnev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid