diff options
author | Mark Spruiell <mes@zeroc.com> | 2007-06-25 16:55:02 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2007-06-25 16:55:53 -0700 |
commit | c014b2b35d34affb7a6da86baf360e0f5298945b (patch) | |
tree | 8d1d0e708532f065a046a3efb7c87e3f42755c42 | |
parent | Merge branch 'master' of ssh://cvs.zeroc.com/home/git/ice (diff) | |
download | ice-c014b2b35d34affb7a6da86baf360e0f5298945b.tar.bz2 ice-c014b2b35d34affb7a6da86baf360e0f5298945b.tar.xz ice-c014b2b35d34affb7a6da86baf360e0f5298945b.zip |
bug 995 - review & minor edits
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Client.cpp | 26 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp | 6 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/CurrentDatabase.h | 3 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Evictor.cpp | 54 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Evictor.h | 8 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/ItemI.h | 1 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/README | 19 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/Server.cpp | 17 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp | 8 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/config.server | 5 | ||||
-rw-r--r-- | cpp/demo/Freeze/customEvictor/db/DB_CONFIG | 2 |
11 files changed, 69 insertions, 80 deletions
diff --git a/cpp/demo/Freeze/customEvictor/Client.cpp b/cpp/demo/Freeze/customEvictor/Client.cpp index 07e576ce3e0..45c0ddae829 100644 --- a/cpp/demo/Freeze/customEvictor/Client.cpp +++ b/cpp/demo/Freeze/customEvictor/Client.cpp @@ -49,7 +49,7 @@ public: // Measures how long it takes to read 'readCount' items at random // IceUtil::Time start = IceUtil::Time::now(); - + try { for(int i = 0; i < readCount; ++i) @@ -58,7 +58,7 @@ public: ostringstream os; os << "P/N " << id; string name = os.str(); - + Ice::Identity identity; identity.name = name; ItemPrx item = ItemPrx::uncheckedCast(_anItem->ice_identity(identity)); @@ -78,7 +78,7 @@ public: } private: - + const ItemPrx _anItem; int _requestsPerSecond; }; @@ -97,16 +97,16 @@ public: virtual void run() { // - // Measure how long it takes to write 'writeCount' items at random + // Measure how long it takes to write 'writeCount' items at random. // IceUtil::Time start = IceUtil::Time::now(); - + try { for(int i = 0; i < writeCount; ++i) { int id = IceUtil::random(objectCount); - + ostringstream os; os << "P/N " << id; string name = os.str(); @@ -114,7 +114,7 @@ public: Ice::Identity identity; identity.name = name; ItemPrx item = ItemPrx::uncheckedCast(_anItem->ice_identity(identity)); - + item->adjustStock(1); } _requestsPerSecond = static_cast<int>(writeCount / (IceUtil::Time::now() - start).toSecondsDouble()); @@ -124,14 +124,14 @@ public: cerr << "Unexpected exception in WriterThread: " << e << endl; } } - + int getRequestsPerSecond() const { return _requestsPerSecond; } private: - + const ItemPrx _anItem; int _requestsPerSecond; }; @@ -141,12 +141,12 @@ int WarehouseClient::run(int argc, char* argv[]) { // - // Retrieve a proxy to one item (any item will do) + // Retrieve a proxy to one item (any item will do). // ItemPrx anItem = ItemPrx::checkedCast(communicator()->propertyToProxy("Item.Proxy")); // - // Start 1 writer and 5 readers + // Start 1 writer and 5 readers. // WriterThreadPtr wt = new WriterThread(anItem); wt->start(); @@ -168,7 +168,7 @@ WarehouseClient::run(int argc, char* argv[]) } // - // Display results: + // Display results. // cout.precision(3); int rpt = wt->getRequestsPerSecond(); @@ -186,6 +186,6 @@ WarehouseClient::run(int argc, char* argv[]) << " ms per request)" << endl; } } - + return EXIT_SUCCESS; } diff --git a/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp index 357cfa69d56..e45b4feb28b 100644 --- a/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp +++ b/cpp/demo/Freeze/customEvictor/CurrentDatabase.cpp @@ -14,7 +14,7 @@ using namespace std; using namespace IceUtil; // -// This implementation is very simple but not restartable, i.e. you +// This implementation is very simple but not restartable, i.e., you // can only create and destroy one CurrentDatabase per process run. // @@ -26,9 +26,8 @@ namespace { // -// We keep a db on each thread +// We keep a db on each thread. // - __thread Database* db = 0; } @@ -48,7 +47,6 @@ CurrentDatabase::~CurrentDatabase() } } - Database& CurrentDatabase::get() { diff --git a/cpp/demo/Freeze/customEvictor/CurrentDatabase.h b/cpp/demo/Freeze/customEvictor/CurrentDatabase.h index dcc0231ce9d..862dee47993 100644 --- a/cpp/demo/Freeze/customEvictor/CurrentDatabase.h +++ b/cpp/demo/Freeze/customEvictor/CurrentDatabase.h @@ -15,9 +15,8 @@ #include <list> // -// Provides a Database object for each thread +// Provides a Database object for each thread. // - class CurrentDatabase { public: diff --git a/cpp/demo/Freeze/customEvictor/Evictor.cpp b/cpp/demo/Freeze/customEvictor/Evictor.cpp index a4b93688396..978d7117a26 100644 --- a/cpp/demo/Freeze/customEvictor/Evictor.cpp +++ b/cpp/demo/Freeze/customEvictor/Evictor.cpp @@ -18,7 +18,7 @@ int cacheMisses = 0; } // -// Cache +// EvictorCache // EvictorCache::EvictorCache(CurrentDatabase& currentDb) : _currentDb(currentDb) @@ -26,7 +26,7 @@ EvictorCache::EvictorCache(CurrentDatabase& currentDb) : } // -// Just returns 0 if object is not found +// Returns 0 if object is not found. // EvictorEntryPtr EvictorCache::load(const Ice::Identity& itemId) @@ -39,15 +39,14 @@ EvictorCache::load(const Ice::Identity& itemId) cout << cacheMisses << " cache misses" << endl; } } - + // - // You can simulate more expensing cache-misses by adding a sleep here: + // You can simulate more expensive cache-misses by adding a sleep here: // // ThreadControl::sleep(Time::milliSeconds(1)); // - // Use a const Database& to avoid starting a transaction - // (just an optimization) + // Use a const Database& to avoid starting a transaction (just an optimization). // const Database& cdb = _currentDb.get(); Database::const_iterator p = cdb.find(itemId.name); @@ -62,7 +61,7 @@ EvictorCache::load(const Ice::Identity& itemId) } // -// Finish to initialize the entry after it has been inserted in the +// Finish initializing the entry after it has been inserted in the // Cache map, but before any other thread can find it. // // pinned() is called while IceUtil::Cache's internal mutex is locked, @@ -80,7 +79,6 @@ EvictorCache::pinned(const EvictorEntryPtr& entry, EvictorCache::Position cp) // // EvictorEntry // - EvictorEntry::EvictorEntry(const ItemIPtr& item) : servant(item), useCount(-1), @@ -91,7 +89,6 @@ EvictorEntry::EvictorEntry(const ItemIPtr& item) : // // Evictor // - Evictor::Evictor(CurrentDatabase& currentDb, int size) : _cache(currentDb), _queueSize(0), @@ -103,20 +100,21 @@ Ice::ObjectPtr Evictor::locate(const Ice::Current& current, Ice::LocalObjectPtr& cookie) { cookie = 0; - + // // Lookup the cookie (EvictorEntry) in the cache; this will call load() // if the entry is not yet in there. - // If we get an entry that was just evicted (stale == true), we try again + // + // If we get an entry that was just evicted (stale == true), we try again. // for(;;) { EvictorEntryPtr entry = _cache.pin(current.id); - + if(entry == 0) { // - // Will raise ObjectNotExistException + // Will raise ObjectNotExistException. // return 0; } @@ -124,20 +122,20 @@ Evictor::locate(const Ice::Current& current, Ice::LocalObjectPtr& cookie) { { // - // Lock _mutex when reading/writing useCount, stale and queuePosition + // Lock _mutex when reading/writing useCount, stale and queuePosition. // Mutex::Lock lock(_mutex); - + if(entry->stale) { // - // Another thread just evicted this entry: try again + // Another thread just evicted this entry; try again. // continue; } - + cookie = entry; - + if(entry->useCount < 0) { entry->useCount = 0; @@ -147,20 +145,20 @@ Evictor::locate(const Ice::Current& current, Ice::LocalObjectPtr& cookie) { _queue.erase(entry->queuePosition); } - + _queue.push_front(entry); entry->queuePosition = _queue.begin(); entry->useCount++; } } - + // - // We have at least one useCount, and servant is immutable + // We have at least one useCount, and servant is immutable. // return entry->servant; } } - + void Evictor::finished(const Ice::Current& current, const Ice::ObjectPtr& servant, const Ice::LocalObjectPtr& cookie) @@ -168,7 +166,7 @@ Evictor::finished(const Ice::Current& current, const Ice::ObjectPtr& servant, if(cookie != 0) { Mutex::Lock lock(_mutex); - + EvictorEntryPtr entry = EvictorEntryPtr::dynamicCast(cookie); assert(entry != 0); @@ -191,13 +189,12 @@ void Evictor::evict() { // - // Called with _mutex locked - // Try to erase the excess entries + // Called with _mutex locked; try to erase the excess entries. // EvictorQueue::reverse_iterator p = _queue.rbegin(); int toErase = (_queueSize - _size); - + while(toErase > 0 && p != _queue.rend()) { // @@ -207,14 +204,14 @@ Evictor::evict() { ++p; } - + if(p != _queue.rend()) { EvictorEntryPtr& entry = *p; assert(!entry->stale); entry->stale = true; _cache.unpin(entry->cachePosition); - + // // Erase returns a normal iterator to the item after the erased item; // and then reverse_iterator() makes q point to the item before it. @@ -225,4 +222,3 @@ Evictor::evict() } } } - diff --git a/cpp/demo/Freeze/customEvictor/Evictor.h b/cpp/demo/Freeze/customEvictor/Evictor.h index d091309a4e2..e0e381551ba 100644 --- a/cpp/demo/Freeze/customEvictor/Evictor.h +++ b/cpp/demo/Freeze/customEvictor/Evictor.h @@ -20,7 +20,7 @@ struct EvictorEntry; typedef IceUtil::Handle<EvictorEntry> EvictorEntryPtr; // -// A map that does not lock-out lookups during loading from storage +// A map that allows lookups while loading from storage. // class EvictorCache : public IceUtil::Cache<Ice::Identity, EvictorEntry> { @@ -39,7 +39,7 @@ private: }; // -// We'll keep our entries in a queue +// We'll keep our entries in a queue. // typedef std::list<EvictorEntryPtr> EvictorQueue; @@ -48,13 +48,13 @@ struct EvictorEntry : public Ice::LocalObject EvictorEntry(const ItemIPtr&); // - // Immutable after initialization / insertion into the Cache map + // Immutable after initialization / insertion into the Cache map. // const Ice::ObjectPtr servant; EvictorCache::Position cachePosition; // - // Protected by the Evictor mutex + // Protected by the Evictor mutex. // EvictorQueue::iterator queuePosition; int useCount; diff --git a/cpp/demo/Freeze/customEvictor/ItemI.h b/cpp/demo/Freeze/customEvictor/ItemI.h index ae3b387f2ba..546e0d2a250 100644 --- a/cpp/demo/Freeze/customEvictor/ItemI.h +++ b/cpp/demo/Freeze/customEvictor/ItemI.h @@ -38,7 +38,6 @@ private: Warehouse::ItemInfo _cachedInfo; IceUtil::Mutex _mutex; }; - typedef IceUtil::Handle<ItemI> ItemIPtr; #endif diff --git a/cpp/demo/Freeze/customEvictor/README b/cpp/demo/Freeze/customEvictor/README index aaa11afba3c..e688bb206b8 100644 --- a/cpp/demo/Freeze/customEvictor/README +++ b/cpp/demo/Freeze/customEvictor/README @@ -34,7 +34,7 @@ with two possible servant locator implementations: underlying map. In particular, any lookup will block while an object is being retrieved from the database. -To use the Evictor, run server with no argument: +To use the Evictor, run the server with no arguments: $ server @@ -50,10 +50,11 @@ the access pattern is random. Client ------ -The client starts six threads, five threads that, in a loop, randomly read -items provided by the server, and one thread that writes these items at -random, also in a loop. After a large number of iterations, the client displays -the average number of requests per second for each thread. +The client starts six threads: five threads that, in a loop, randomly +read items provided by the server, and one thread that writes these +items at random, also in a loop. After a large number of iterations, +the client displays the average number of requests per second for each +thread. With the default configuration, cache misses are reasonably costly, so you should see a performance advantage when using the @@ -75,8 +76,8 @@ cache misses become fairly cheap. Use db/DB_CONFIG to set the Berkeley DB environment cache size. -The default cache is is 256KB; with a cache size of 128KB, the +The default cache size is 256KB; with a cache size of 128KB, the performance difference between Evictor and EvictorBase increases, -since the larger number of cache misses requires more data to be -read from disk. With a cache size of 100MB, the performance -difference between the two evictor implementations becomes very small. +since the larger number of cache misses requires more data to be read +from disk. With a cache size of 100MB, the performance difference +between the two evictor implementations becomes very small. diff --git a/cpp/demo/Freeze/customEvictor/Server.cpp b/cpp/demo/Freeze/customEvictor/Server.cpp index 190f684e4e1..645e1b48ea8 100644 --- a/cpp/demo/Freeze/customEvictor/Server.cpp +++ b/cpp/demo/Freeze/customEvictor/Server.cpp @@ -39,7 +39,7 @@ int WarehouseServer::run(int argc, char* argv[]) { bool useSimpleEvictor = argc > 1 && string(argv[1]) == "simple"; - + if(useSimpleEvictor) { cout << "Using SimpleEvictor" << endl; @@ -56,21 +56,22 @@ WarehouseServer::run(int argc, char* argv[]) { // - // Open our database, a Freeze dictionay + // Open our database, a Freeze dictionary. // Freeze::ConnectionPtr connection = Freeze::createConnection(communicator(), envName); Database db(connection, dbName); - + if(db.empty()) { cout << "Creating new database..." << flush; + // - // Populate database with objectCount entries + // Populate database with objectCount entries. // ItemInfo info; - + connection->beginTransaction(); - + for(int i = 0; i < objectCount; ++i) { ostringstream os; @@ -80,7 +81,7 @@ WarehouseServer::run(int argc, char* argv[]) info.unitPrice = i + 0.95f; info.quantityInStock = i; info.filler = string(5000, 'x'); - + db.put(Database::value_type(name, info)); } connection->currentTransaction()->commit(); @@ -91,7 +92,7 @@ WarehouseServer::run(int argc, char* argv[]) CurrentDatabase currentDb(communicator(), envName, dbName); // - // This servant locator (evictor) will intercept all categories + // This servant locator (evictor) will intercept all categories. // if(useSimpleEvictor) { diff --git a/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp b/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp index 18b01e1d78f..a0e3c1e8752 100644 --- a/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp +++ b/cpp/demo/Freeze/customEvictor/SimpleEvictor.cpp @@ -24,7 +24,6 @@ SimpleEvictor::SimpleEvictor(CurrentDatabase& currentDb, int size) : { } - Ice::ObjectPtr SimpleEvictor::add(const Ice::Current& current, Ice::LocalObjectPtr& cookie) { @@ -40,13 +39,12 @@ SimpleEvictor::add(const Ice::Current& current, Ice::LocalObjectPtr& cookie) } // - // You can simulate more expensing cache-misses by adding a sleep here: + // You can simulate more expensive cache-misses by adding a sleep here: // // ThreadControl::sleep(Time::milliSeconds(1)); // - // Use a const Database& to avoid starting a transaction - // (just an optimization) + // Use a const Database& to avoid starting a transaction (just an optimization). // const Database& cdb = _currentDb.get(); Database::const_iterator p = cdb.find(current.id.name); @@ -64,6 +62,6 @@ void SimpleEvictor::evict(const Ice::ObjectPtr&, const Ice::LocalObjectPtr&) { // - // Nothing to do + // Nothing to do. // } diff --git a/cpp/demo/Freeze/customEvictor/config.server b/cpp/demo/Freeze/customEvictor/config.server index b77445b9d93..a319b607961 100644 --- a/cpp/demo/Freeze/customEvictor/config.server +++ b/cpp/demo/Freeze/customEvictor/config.server @@ -1,6 +1,6 @@ # -# The server creates one single object adapter with the name -# "Warehouse". The following line sets the endpoints for this adapter. +# The server creates an object adapter with the name "Warehouse". The +# following line sets the endpoints for this adapter. # Warehouse.Endpoints=tcp -p 10000 @@ -10,4 +10,3 @@ Warehouse.Endpoints=tcp -p 10000 # Ice.ThreadPool.Server.Size=10 Ice.ThreadPool.Server.SizeWarn=-1 - diff --git a/cpp/demo/Freeze/customEvictor/db/DB_CONFIG b/cpp/demo/Freeze/customEvictor/db/DB_CONFIG index 44cc87c95e6..033e592d5b6 100644 --- a/cpp/demo/Freeze/customEvictor/db/DB_CONFIG +++ b/cpp/demo/Freeze/customEvictor/db/DB_CONFIG @@ -6,5 +6,3 @@ # about 100MB #set_cachesize 0 100000000 1 - - |