[asterisk-scf-commits] asterisk-scf/integration/media_rtp_pjmedia.git branch "thread_reduction" created.
Commits to the Asterisk SCF project code repositories
asterisk-scf-commits at lists.digium.com
Tue Jul 24 10:00:14 CDT 2012
branch "thread_reduction" has been created
at 78dd865f792d26aa6e750f6d19f6153211c3282b (commit)
- Log -----------------------------------------------------------------
commit 78dd865f792d26aa6e750f6d19f6153211c3282b
Author: Brent Eagles <beagles at digium.com>
Date: Tue Jul 24 12:16:37 2012 -0230
Experimental changes aimed at constraining resource consumption when there are
many concurrent sessions.
- Instantiate only one ioqueue per component
- Instantiate a single media endpoint and share among the sessions. The
endpoint is the source of thread allocations so constraining how many of these
are created is essential.
diff --git a/src/PJMEDIAEndpoint.cpp b/src/PJMEDIAEndpoint.cpp
index 97092ec..1ba53fc 100644
--- a/src/PJMEDIAEndpoint.cpp
+++ b/src/PJMEDIAEndpoint.cpp
@@ -23,20 +23,31 @@ using namespace AsteriskSCF::PJMEDIARTP;
using namespace AsteriskSCF::System::V1;
using namespace AsteriskSCF::PJUtil;
+const int MaxThreads = 16;
+
+boost::mutex PJMEDIAEndpoint::mEndpointMutex;
+PJMEDIAEndpointPtr PJMEDIAEndpoint::mEndpointInstance;
+
PJMEDIAEndpoint::~PJMEDIAEndpoint()
{
pjmedia_endpt_destroy(mEndpoint);
}
-PJMEDIAEndpointPtr AsteriskSCF::PJMEDIARTP::PJMEDIAEndpoint::create(const PJMEDIAEnvironmentPtr& env)
+PJMEDIAEndpointPtr AsteriskSCF::PJMEDIARTP::PJMEDIAEndpoint::get(const PJMEDIAEnvironmentPtr& env)
{
+ boost::lock_guard<boost::mutex> lock(mEndpointMutex);
+ if (mEndpointInstance)
+ {
+ return mEndpointInstance;
+ }
pjmedia_endpt* t;
- pj_status_t result = pjmedia_endpt_create(env->poolFactory(), 0, 1, &t);
+ pj_status_t result = pjmedia_endpt_create(env->poolFactory(), env->ioQueue(), MaxThreads, &t);
if (fail(result))
{
throw InternalInitializationException("Unable to create media endpoint!");
}
- return PJMEDIAEndpointPtr(new PJMEDIAEndpoint(t));
+ mEndpointInstance.reset(new PJMEDIAEndpoint(t));
+ return mEndpointInstance;
}
PJMEDIAEndpoint::PJMEDIAEndpoint(pjmedia_endpt* endpt) :
diff --git a/src/PJMEDIAEndpoint.h b/src/PJMEDIAEndpoint.h
index 93c614e..674a82d 100644
--- a/src/PJMEDIAEndpoint.h
+++ b/src/PJMEDIAEndpoint.h
@@ -18,6 +18,7 @@
#include "PJMEDIAEnvironment.h"
#include <boost/shared_ptr.hpp>
+#include <boost/thread/mutex.hpp>
//
// forward declarations.
@@ -43,13 +44,16 @@ public:
return mEndpoint;
}
- static PJMEDIAEndpointPtr create(const PJMEDIAEnvironmentPtr& environ);
+ static PJMEDIAEndpointPtr get(const PJMEDIAEnvironmentPtr& environ);
private:
pjmedia_endpt* mEndpoint;
PJMEDIAEndpoint(pjmedia_endpt* endpoint);
+ static boost::mutex mEndpointMutex;
+ static PJMEDIAEndpointPtr mEndpointInstance;
+
//
// Hidden and unimplemented.
//
diff --git a/src/PJMEDIAEnvironment.cpp b/src/PJMEDIAEnvironment.cpp
index 2983073..89f7059 100644
--- a/src/PJMEDIAEnvironment.cpp
+++ b/src/PJMEDIAEnvironment.cpp
@@ -27,6 +27,14 @@ using namespace AsteriskSCF::PJMEDIARTP;
using namespace AsteriskSCF::System::V1;
using namespace AsteriskSCF::PJUtil;
+PJMEDIAEnvironment::~PJMEDIAEnvironment()
+{
+ if (mIOQueue)
+ {
+ pj_ioqueue_destroy(mIOQueue);
+ }
+}
+
//
// The main work of creating the various objects is done by the factory, not the PJMEDIAEnvironment constructor.
//
@@ -40,7 +48,8 @@ PJMEDIAEnvironment::PJMEDIAEnvironment(const PJLIBConfigurationPtr& libCfg,
const RTPConfigurationPtr& configObject) :
mPJLIBConfig(libCfg),
mConfiguration(configObject),
- mCachingPool(new pj_caching_pool)
+ mCachingPool(new pj_caching_pool),
+ mIOQueue(0)
{
//
// I find this practice a little sketchy since the pointers that might be retrieve through the accessors *must*
@@ -53,4 +62,5 @@ PJMEDIAEnvironment::PJMEDIAEnvironment(const PJLIBConfigurationPtr& libCfg,
// TODO: should these values come from configuration.
//
mMemoryPool = pj_pool_create(mPoolFactory, "media_rtp_pjmedia", 1024, 1024, 0);
+ pj_status_t ioqueueStatus = pj_ioqueue_create(mMemoryPool, PJ_IOQUEUE_MAX_HANDLES, &mIOQueue);
}
diff --git a/src/PJMEDIAEnvironment.h b/src/PJMEDIAEnvironment.h
index 67e604a..418d48e 100644
--- a/src/PJMEDIAEnvironment.h
+++ b/src/PJMEDIAEnvironment.h
@@ -29,6 +29,7 @@ struct pj_pool_factory;
struct pjmedia_endpt;
struct pj_pool_t;
struct pj_caching_pool;
+struct pj_ioqueue_t;
namespace AsteriskSCF
{
@@ -58,6 +59,7 @@ typedef boost::shared_ptr<PJMEDIAEnvironment> PJMEDIAEnvironmentPtr;
class PJMEDIAEnvironment
{
public:
+ virtual ~PJMEDIAEnvironment();
/**
* Get generic configuration object.
@@ -110,6 +112,11 @@ public:
return mMemoryPool;
}
+ pj_ioqueue_t* ioQueue() const
+ {
+ return mIOQueue;
+ }
+
/**
* Create an instance of the object based on the Ice properties.
*/
@@ -122,10 +129,12 @@ private:
pj_pool_factory* mPoolFactory;
pj_pool_t* mMemoryPool;
+ pj_ioqueue_t* mIOQueue;
boost::shared_ptr<pj_caching_pool> mCachingPool;
PJMEDIAEnvironment(const PJLIBConfigurationPtr& libConfig,
const RTPConfigurationPtr& configObject);
+
};
} /* End of namespace PJMEDIARTP */
diff --git a/src/RTPSession.cpp b/src/RTPSession.cpp
index ce5ba9b..fca1d53 100644
--- a/src/RTPSession.cpp
+++ b/src/RTPSession.cpp
@@ -515,7 +515,7 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter,
const ConfigurationServiceImplPtr& configurationService) :
mOperationContextCache(OperationContextCache::create(DEFAULT_TTL_SECONDS)),
mEnvironment(env),
- mEndpoint(PJMEDIAEndpoint::create(env)),
+ mEndpoint(PJMEDIAEndpoint::get(env)),
mId(id),
mAdapter(adapter),
mFormats(params->formats),
@@ -574,7 +574,7 @@ RTPSessionImpl::RTPSessionImpl(const Ice::ObjectAdapterPtr& adapter,
const RTPReplicationContextPtr& replicationContext,
const ConfigurationServiceImplPtr& configurationService) :
mEnvironment(env),
- mEndpoint(PJMEDIAEndpoint::create(env)),
+ mEndpoint(PJMEDIAEndpoint::get(env)),
mId(sessionIdentity),
mAdapter(adapter),
mFormats(formats),
-----------------------------------------------------------------------
--
asterisk-scf/integration/media_rtp_pjmedia.git
More information about the asterisk-scf-commits
mailing list