|
|
|
|||||
|
Why concurrent access to FreezeMap is so slow?
When I test the concurrent access to FreezeMap,I found it is much slower than single-thread method.My code like following:
Code:
ObjectAdapterPtr g_pAdapter;
vector<string> g_GetNamesFromMap(long beginTime,long endTime)
{
vector<string> back;
Freeze::ConnectionPtr pConn = Freeze::createConnection(g_pAdapter->getCommunicator(), "db");
IHisDataMap hisDataMap(pConn, "map");
IHisDataMap::const_iterator pEnd = hisDataMap.upperBoundForTime(endTime);
IHisDataMap::const_iterator pos;
for(pos = hisDataMap.lowerBoundForTime(beginTime);pos!=pEnd;++pos)
{
back.push_back(pos->first);
}
return back;
}
vector<string> g_SetNamesToMap(string name,long time)
{
Freeze::ConnectionPtr pConn = Freeze::createConnection(g_pAdapter->getCommunicator(), "db");
IHisDataMap hisDataMap(pConn, "map");
IHisDataMap::iterator pos = hisDataMap.find(name);
if(pos != hisDataMap.end())
{
pos.set(time);
}else
{
hisDataMap.insert(make_pair(name, time));
}
}
void JobThread::run()
{
m_bRunning = true;
IceUtil::Time sleepTime = IceUtil::Time::milliSeconds(1000);
while(true)
{
if(!m_bRunning)
{
break;
}else
{
vector<string> names = g_GetNamesFromMap(0,ULONG_MAX);
}
ThreadControl::sleep(sleepTime);
}
}
void main()
{
//Init communicator and g_pAdapter
.............................
int iThreadNum = 30;
for(int i=0;i<iThreadNum;++i)
{
JobThread pThread = new JobThread();
pThread->start();
}
}
2. When some threads are invoking g_GetNamesFromMap, I will call g_SetNamesToMap to update the map. In this case, do I have to serialize the two function or just call g_SetNamesToMap directly?
__________________
Tang Fan ShenZhen Yijin Platform Network Technology Co.,Ltd Project: Stock quotation server |
|
|||||
|
vow! So quick response in weekend. Thank you a lot!
Quote:
Code:
void JobThread::run()
{
m_bRunning = true;
IceUtil::Time sleepTime = IceUtil::Time::milliSeconds(1000);
while(true)
{
if(!m_bRunning)
{
break;
}else
{
long beginPos = GetTickCount();
vector<string> names = g_GetNamesFromMap(0,ULONG_MAX);
long endPos = GetTickCount();
printf("g_GetNamesFromMap takes %d\n",endPos-beginPos);
}
ThreadControl::sleep(sleepTime);
}
}
![]()
__________________
Tang Fan ShenZhen Yijin Platform Network Technology Co.,Ltd Project: Stock quotation server |
|
||||||
|
Another improvement would be to keep a Map opened in your main thread:
Code:
Freeze::ConnectionPtr pConn = Freeze::createConnection(g_pAdapter->getCommunicator(), "db"); IHisDataMap hisDataMap(pConn, "map"); Cheers, Bernard |
|
|||||
|
There is huge distance between 33s and 600ms. I guess I must miss some important configuration in DB_CONFIG. My DB_CONFIG is:
Quote:
__________________
Tang Fan ShenZhen Yijin Platform Network Technology Co.,Ltd Project: Stock quotation server |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Slow callback sample | burghboy | Help Center | 7 | 02-02-2007 09:43 AM |
| why Icegrid very slow? | ChenQingQing | Help Center | 10 | 05-26-2006 06:04 AM |
| FreezeMap lazy initialize | xdm | Help Center | 3 | 03-01-2006 11:07 PM |
| Integration of functional/concurrent processes languages? | skropp | Comments | 1 | 01-26-2006 06:08 PM |
| FreezeMap Use Clarification | Ken Carpenter | Comments | 11 | 03-01-2003 06:42 AM |