Author: kpvdr
Date: 2009-01-08 09:53:33 -0500 (Thu, 08 Jan 2009)
New Revision: 3035
Modified:
store/trunk/cpp/lib/MessageStoreImpl.cpp
store/trunk/cpp/lib/MessageStoreImpl.h
Log:
Improved hash function gives more even distribution of queues across 29 dirs
Modified: store/trunk/cpp/lib/MessageStoreImpl.cpp
===================================================================
--- store/trunk/cpp/lib/MessageStoreImpl.cpp 2009-01-07 20:10:31 UTC (rev 3034)
+++ store/trunk/cpp/lib/MessageStoreImpl.cpp 2009-01-08 14:53:33 UTC (rev 3035)
@@ -1729,15 +1729,20 @@
return getJrnlDir(queue.getName().c_str());
}
+u_int32_t MessageStoreImpl::bHash(const std::string str)
+{
+ // Daniel Bernstein hash fn
+ u_int32_t h = 0;
+ for (std::string::const_iterator i = str.begin(); i < str.end(); i++)
+ h = 33*h + *i;
+ return h;
+}
+
std::string MessageStoreImpl::getJrnlDir(const char* queueName) //for exmaple /var/rhm/ +
queueDir/
{
std::stringstream dir;
dir << getJrnlBaseDir() << std::hex << std::setfill('0')
<< std::setw(4);
- u_int32_t count = 0;
- for (u_int32_t i = 0; i < strlen(queueName); i++) {
- count += queueName[i];
- }
- dir << (count % 29); // Use a prime number for better distribution across dirs
+ dir << (bHash(queueName) % 29); // Use a prime number for better distribution
across dirs
dir << "/" << queueName << "/";
return dir.str();
}
Modified: store/trunk/cpp/lib/MessageStoreImpl.h
===================================================================
--- store/trunk/cpp/lib/MessageStoreImpl.h 2009-01-07 20:10:31 UTC (rev 3034)
+++ store/trunk/cpp/lib/MessageStoreImpl.h 2009-01-08 14:53:33 UTC (rev 3035)
@@ -241,6 +241,7 @@
// journal functions
void createJrnlQueue(const qpid::broker::PersistableQueue& queue);
+ u_int32_t bHash(const std::string str);
std::string getJrnlDir(const qpid::broker::PersistableQueue& queue); //for
exmaple /var/rhm/ + queueDir/
std::string getJrnlDir(const char* queueName);
std::string getJrnlBaseDir();
Show replies by date