The PooledClassFactory does not work how I expect it to in my code.
I have an initial pool size >0 and preinitializepool=true but no instances of my class are created on server initialization.
I use C# attributes to specify the class factory.
Furthermore it looks like it that after a period of time my instances get destroyed
I noticed in the code that PooledClassFactory now inherits from ExpiringClassFactory, could this be the cause?
Attached is the SuperTcpChatServer sample but modified so it uses PooledClassFactory.
Can you investigate what’s wrong or explain me good usage of the class?
Factory deletes service instances not used for some time. In one of PoolFactory modes the pool can grow really large under heavy load peaks. There is no need to store all service instances once the server load returns to normal values.
Let me describe the factory settings more detailed.
The PooledClassFactory attribute has 4 parameters:
PoolBehavior
PoolSize
PreInitializePool
Timeout
Timeout - if the service instance was not acquired from the pool for at least Timeout seconds it will be considered expired.
PoolBehavior - this parameter has 3 possible values that define the mode pool works in: PoolBehavior.CreateAdditional, PoolBehavior.Wait and PoolBehavior.Fail
PoolBehavior.CreateAdditional actually defines a pool of infinite size. This means that when a request comes in and there is no service instances available in the pool then a new one is created. This helps to cope with high request-per-second peaks. Also this is why the service instances expiration is needed - it removes instances that are no longer required once the load peak ends. In this mode parameters PoolSize and PreInitializePool are ignored.
PoolBehavior.Wait and PoolBehavior.Fail are used to define a finite-size pool that accordingly either waits or throws an error when a instance is requested from an empty pool. In this mode
PoolSize defines pool size
PreInitializePool defines if service instances should be pre-acquired on server startup.
I would have expected exactly the behaviour you describe except for the fact that PoolSize & PreInitializePool are ignored in CreateAdditional mode.
Creating an instance takes a considerable time in my case (3rd party software, internet connections, …).
I would like to start my service with a large number of services but still allow it to increase in the unlikely event we exceed the poolsize. I would then also like to have an option to decide whether to expire the extra services after a timout (negative timeout?).
This suggestion makes the API more intuitive IMO & it still allows your behaviour (createadditional with poolsize=0)
FYI: This post is triggered by some connection issues we have in our customer base since we moved from RO v6 to RO v9 (note: I am still investigating if changes in RO are the cause of the issue)
This sounds reasonable. I’ve changed the PooledClassFactory by enabling pool pre-inialization in all modes. Alos setting Timeout to 0 or -1 now means no timeout at all.
These changes will be available in the next Beta build.
Another question: Will preinitialize + expiration enable only expire up to the initialpoolsize?
This seems like the most logical choice - always have services but potentially more.