summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/IceGrid/Internal.ice10
-rw-r--r--cpp/src/IceGrid/NodeI.cpp51
-rw-r--r--cpp/src/IceGrid/NodeI.h9
-rw-r--r--cpp/src/IceGrid/RegistryI.cpp9
-rw-r--r--cpp/src/IceGrid/RegistryI.h3
-rw-r--r--cpp/src/IceGrid/ServerCache.cpp1
6 files changed, 49 insertions, 34 deletions
diff --git a/cpp/src/IceGrid/Internal.ice b/cpp/src/IceGrid/Internal.ice
index 20fd20c133b..f3307dd05d8 100644
--- a/cpp/src/IceGrid/Internal.ice
+++ b/cpp/src/IceGrid/Internal.ice
@@ -332,19 +332,11 @@ interface Registry
* registered and currently active.
*
**/
- NodeSession* registerNode(string name, Node* nd)
+ NodeSession* registerNode(string name, Node* nd, out NodeObserver* observer)
throws NodeActiveException;
/**
*
- * Get the node observer object. This is used by nodes to publish
- * updates about the state of the nodes (server up/down, etc).
- *
- **/
- NodeObserver* getNodeObserver();
-
- /**
- *
* Shutdown the registry.
*
**/
diff --git a/cpp/src/IceGrid/NodeI.cpp b/cpp/src/IceGrid/NodeI.cpp
index 3ce3edb4c7e..86facd869f8 100644
--- a/cpp/src/IceGrid/NodeI.cpp
+++ b/cpp/src/IceGrid/NodeI.cpp
@@ -217,9 +217,6 @@ NodeI::NodeI(const Ice::ObjectAdapterPtr& adapter,
_serversDir = dataDir + (dataDir[dataDir.length() - 1] == '/' ? "" : "/") + "servers";
_tmpDir = dataDir + (dataDir[dataDir.length() - 1] == '/' ? "" : "/") + "tmp";
- Ice::ObjectPrx registry = getCommunicator()->stringToProxy("IceGrid/Registry@IceGrid.Registry.Internal");
- _observer = RegistryPrx::uncheckedCast(registry)->getNodeObserver();
-
#if defined(_WIN32)
PDH_STATUS err = PdhOpenQuery(0, 0, &_query);
if(err != ERROR_SUCCESS)
@@ -237,6 +234,12 @@ NodeI::NodeI(const Ice::ObjectAdapterPtr& adapter,
Ice::Warning out(_traceLevels->logger);
out << "can't add performance counter:\n" << ex;
}
+ _usages1.insert(_usages1.end(), 1 * 60 / 5, 0); // 1 sample every 5 seconds during 1 minutes.
+ _usages5.insert(_usages5.end(), 5 * 60 / 5, 0); // 1 sample every 5 seconds during 5 minutes.
+ _usages15.insert(_usages15.end(), 15 * 60 / 5, 0); // 1 sample every 5 seconds during 15 minutes.
+ _last1Total = 0;
+ _last5Total = 0;
+ _last15Total = 0;
#else
#if defined(__linux)
_nproc = static_cast<int>(sysconf(_SC_NPROCESSORS_ONLN));
@@ -528,6 +531,7 @@ NodeI::getTraceLevels() const
NodeObserverPrx
NodeI::getObserver() const
{
+ Lock sync(_sessionMutex);
return _observer;
}
@@ -539,10 +543,11 @@ NodeI::getSession() const
}
void
-NodeI::setSession(const NodeSessionPrx& session)
+NodeI::setSession(const NodeSessionPrx& session, const NodeObserverPrx& observer)
{
Lock sync(_sessionMutex);
_session = session;
+ _observer = observer;
}
void
@@ -559,19 +564,32 @@ NodeI::keepAlive()
//
// TODO: Use CPU utilization
//
- if(PdhCollectQueryData(_query) != ERROR_SUCCESS)
- {
- // TODO: WARNING
- info.load = 1.0f;
- }
- else
+ int usage = 100;
+ if(PdhCollectQueryData(_query) == ERROR_SUCCESS)
{
DWORD type;
PDH_FMT_COUNTERVALUE value;
PdhGetFormattedCounterValue(_counter, PDH_FMT_LONG, &type, &value);
- info.load = static_cast<float>(value.longValue) / 100.0f;
+ usage = static_cast<int>(value.longValue);
}
- info.nProcessors = 1; // TODO
+
+ _last1Total += usage - _usages1.back();
+ _last5Total += usage - _usages5.back();
+ _last15Total += usage - _usages15.back();
+
+ _usages1.pop_back();
+ _usages5.pop_back();
+ _usages15.pop_back();
+ _usages1.push_front(usage);
+ _usages5.push_front(usage);
+ _usages15.push_front(usage);
+
+ info.load1 = static_cast<float>(_last1Total) / _usages1.size();
+ info.load5 = static_cast<float>(_last5Total) / _usages5.size();
+ info.load15 = static_cast<float>(_last15Total) / _usages15.size();
+ info.nProcessors = 1;
+
+ cerr << info.load1 << " " << info.load5 << " " << info.load15 << endl;
#elif defined(__sun) || defined(__linux) || defined(__APPLE__)
//
// We use the load average divided by the number of
@@ -585,7 +603,9 @@ NodeI::keepAlive()
info.load15 = static_cast<float>(loadAvg[2]);
info.nProcessors = _nproc;
#else
- info.load = 1.0f;
+ info.load1 = 1.0f;
+ info.load5 = 1.0f;
+ info.load15 = 1.0f;
info.nProcessors = 1;
#endif
@@ -593,7 +613,7 @@ NodeI::keepAlive()
}
catch(const Ice::LocalException&)
{
- setSession(0);
+ setSession(0, 0);
}
}
else
@@ -601,7 +621,8 @@ NodeI::keepAlive()
try
{
Ice::ObjectPrx registry = getCommunicator()->stringToProxy("IceGrid/Registry@IceGrid.Registry.Internal");
- setSession(RegistryPrx::uncheckedCast(registry)->registerNode(_name, _proxy));
+ NodeObserverPrx observer;
+ setSession(RegistryPrx::uncheckedCast(registry)->registerNode(_name, _proxy, observer), observer);
checkConsistency();
}
catch(const NodeActiveException&)
diff --git a/cpp/src/IceGrid/NodeI.h b/cpp/src/IceGrid/NodeI.h
index 30555e66860..43484f2aff4 100644
--- a/cpp/src/IceGrid/NodeI.h
+++ b/cpp/src/IceGrid/NodeI.h
@@ -15,6 +15,7 @@
#ifdef _WIN32
# include <pdh.h> // Performance data helper API
+# include <deque>
#endif
namespace IceGrid
@@ -53,7 +54,7 @@ public:
NodeObserverPrx getObserver() const;
NodeSessionPrx getSession() const;
- void setSession(const NodeSessionPrx&);
+ void setSession(const NodeSessionPrx&, const NodeObserverPrx&);
void keepAlive();
void stop();
@@ -81,6 +82,12 @@ private:
#ifdef _WIN32
HQUERY _query;
HCOUNTER _counter;
+ std::deque<int> _usages1;
+ std::deque<int> _usages5;
+ std::deque<int> _usages15;
+ int _last1Total;
+ int _last5Total;
+ int _last15Total;
#else
int _nproc;
#endif
diff --git a/cpp/src/IceGrid/RegistryI.cpp b/cpp/src/IceGrid/RegistryI.cpp
index c3f163f1321..5160c20ac28 100644
--- a/cpp/src/IceGrid/RegistryI.cpp
+++ b/cpp/src/IceGrid/RegistryI.cpp
@@ -399,21 +399,16 @@ RegistryI::stop()
}
NodeSessionPrx
-RegistryI::registerNode(const std::string& name, const NodePrx& node, const Ice::Current& c)
+RegistryI::registerNode(const std::string& name, const NodePrx& node, NodeObserverPrx& obs, const Ice::Current& c)
{
NodePrx n = NodePrx::uncheckedCast(node->ice_timeout(_nodeSessionTimeout * 1000));
NodeSessionIPtr session = new NodeSessionI(_database, name, n);
NodeSessionPrx proxy = NodeSessionPrx::uncheckedCast(c.adapter->addWithUUID(session));
_reaper->add(proxy, session);
+ obs = _nodeObserver;
return proxy;
}
-NodeObserverPrx
-RegistryI::getNodeObserver(const Ice::Current& current)
-{
- return _nodeObserver;
-}
-
void
RegistryI::shutdown(const Ice::Current& current)
{
diff --git a/cpp/src/IceGrid/RegistryI.h b/cpp/src/IceGrid/RegistryI.h
index 7932e3cac42..c3a1c21697e 100644
--- a/cpp/src/IceGrid/RegistryI.h
+++ b/cpp/src/IceGrid/RegistryI.h
@@ -32,8 +32,7 @@ public:
bool start(bool);
void stop();
- virtual NodeSessionPrx registerNode(const std::string&, const NodePrx&, const Ice::Current&);
- virtual NodeObserverPrx getNodeObserver(const Ice::Current&);
+ virtual NodeSessionPrx registerNode(const std::string&, const NodePrx&, NodeObserverPrx&, const Ice::Current&);
virtual void shutdown(const Ice::Current& current);
virtual IceStorm::TopicManagerPrx getTopicManager();
diff --git a/cpp/src/IceGrid/ServerCache.cpp b/cpp/src/IceGrid/ServerCache.cpp
index 0703e26df65..7d4a39329fb 100644
--- a/cpp/src/IceGrid/ServerCache.cpp
+++ b/cpp/src/IceGrid/ServerCache.cpp
@@ -353,6 +353,7 @@ ServerEntry::getLoad(LoadSample sample) const
return load.load15 * factor;
default:
assert(false);
+ return 1.0f;
}
}