Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
45bafea1
Commit
45bafea1
authored
Jan 29, 2014
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(UInterface): убрал использование "дорогого" timestamp в кэше, перешёл на подсчёт обращений.
parent
b6bccc10
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
53 deletions
+17
-53
UInterface.h
include/UInterface.h
+8
-37
UInterface.cc
src/Interfaces/UInterface.cc
+9
-16
No files found.
include/UInterface.h
View file @
45bafea1
...
@@ -256,12 +256,12 @@ class UInterface
...
@@ -256,12 +256,12 @@ class UInterface
class
CacheOfResolve
class
CacheOfResolve
{
{
public
:
public
:
CacheOfResolve
(
unsigned
int
maxsize
,
int
cleantime
)
:
CacheOfResolve
(
unsigned
int
maxsize
,
int
cleancount
=
20
)
:
MaxSize
(
maxsize
),
CleanTime
(
cleantime
){};
MaxSize
(
maxsize
),
minCallCount
(
cleancount
){};
~
CacheOfResolve
(){};
~
CacheOfResolve
(){};
UniSetTypes
::
ObjectPtr
resolve
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
throw
(
UniSetTypes
::
NameNotFound
);
UniSetTypes
::
ObjectPtr
resolve
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
throw
(
UniSetTypes
::
NameNotFound
);
void
cache
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
,
UniSetTypes
::
ObjectVar
ptr
)
const
;
void
cache
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
,
UniSetTypes
::
ObjectVar
ptr
)
const
;
void
erase
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
;
void
erase
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
;
inline
void
setMaxSize
(
unsigned
int
ms
)
inline
void
setMaxSize
(
unsigned
int
ms
)
...
@@ -269,8 +269,6 @@ class UInterface
...
@@ -269,8 +269,6 @@ class UInterface
MaxSize
=
ms
;
MaxSize
=
ms
;
};
};
// void setCleanTime();
protected
:
protected
:
CacheOfResolve
(){};
CacheOfResolve
(){};
...
@@ -283,52 +281,25 @@ class UInterface
...
@@ -283,52 +281,25 @@ class UInterface
mcache
.
clear
();
mcache
.
clear
();
};
};
/*!
\todo можно добавить поле CleanTime для каждой ссылки отдельно...
*/
struct
Info
struct
Info
{
{
Info
(
UniSetTypes
::
ObjectVar
ptr
,
time_t
tm
=
0
)
:
Info
(
UniSetTypes
::
ObjectVar
ptr
)
:
ptr
(
ptr
),
ncall
(
0
){}
ptr
(
ptr
)
Info
()
:
ptr
(
NULL
),
ncall
(
0
){}
{
if
(
!
tm
)
timestamp
=
time
(
NULL
);
}
Info
()
:
ptr
(
NULL
),
timestamp
(
0
){};
UniSetTypes
::
ObjectVar
ptr
;
UniSetTypes
::
ObjectVar
ptr
;
time_t
timestamp
;
// время последнего обращения
unsigned
long
ncall
;
// счётчик обращений
bool
operator
<
(
const
CacheOfResolve
::
Info
&
rhs
)
const
bool
operator
<
(
const
CacheOfResolve
::
Info
&
rhs
)
const
{
{
return
this
->
timestamp
<
rhs
.
timestamp
;
return
this
->
ncall
>
rhs
.
ncall
;
}
}
};
};
typedef
std
::
map
<
int
,
Info
>
CacheMap
;
typedef
std
::
map
<
int
,
Info
>
CacheMap
;
mutable
CacheMap
mcache
;
mutable
CacheMap
mcache
;
mutable
UniSetTypes
::
uniset_rwmutex
cmutex
;
mutable
UniSetTypes
::
uniset_rwmutex
cmutex
;
unsigned
int
MaxSize
;
/*!< максимальный размер кэша */
unsigned
int
MaxSize
;
/*!< максимальный размер кэша */
unsigned
int
CleanTime
;
/*!< период устаревания ссылок [мин] */
unsigned
int
minCallCount
;
/*!< минимальное количество вызовов, меньше которого ссылка считается устаревшей */
/*
// В последствии написать функцию для использования
// remove_if
typedef std::pair<int, Info> CacheItem;
// функция-объект для поиска устаревших(по времени) ссылок
struct OldRef_eq: public unary_function<CacheItem, bool>
{
OldRef_eq(time_t tm):tm(tm){}
bool operator()( const CacheItem& inf ) const
{
return inf.timestamp < tm;
}
time_t tm;
};
*/
};
};
void
initBackId
(
UniSetTypes
::
ObjectId
backid
);
void
initBackId
(
UniSetTypes
::
ObjectId
backid
);
...
...
src/Interfaces/UInterface.cc
View file @
45bafea1
...
@@ -44,7 +44,7 @@ UInterface::UInterface( const UniSetTypes::Configuration* _uconf ):
...
@@ -44,7 +44,7 @@ UInterface::UInterface( const UniSetTypes::Configuration* _uconf ):
rep
(
_uconf
),
rep
(
_uconf
),
myid
(
UniSetTypes
::
DefaultObjectId
),
myid
(
UniSetTypes
::
DefaultObjectId
),
orb
(
CORBA
::
ORB
::
_nil
()),
orb
(
CORBA
::
ORB
::
_nil
()),
rcache
(
100
,
5
),
rcache
(
100
,
20
),
oind
(
_uconf
->
oind
),
oind
(
_uconf
->
oind
),
uconf
(
_uconf
)
uconf
(
_uconf
)
{
{
...
@@ -55,7 +55,7 @@ UInterface::UInterface( const ObjectId backid, CORBA::ORB_var orb, ObjectIndex*
...
@@ -55,7 +55,7 @@ UInterface::UInterface( const ObjectId backid, CORBA::ORB_var orb, ObjectIndex*
rep
(
UniSetTypes
::
conf
),
rep
(
UniSetTypes
::
conf
),
myid
(
backid
),
myid
(
backid
),
orb
(
orb
),
orb
(
orb
),
rcache
(
200
,
12
0
),
rcache
(
200
,
4
0
),
oind
(
_oind
),
oind
(
_oind
),
uconf
(
UniSetTypes
::
conf
)
uconf
(
UniSetTypes
::
conf
)
{
{
...
@@ -1065,14 +1065,11 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
...
@@ -1065,14 +1065,11 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
{
{
UniSetTypes
::
uniset_rwmutex_rlock
l
(
cmutex
);
UniSetTypes
::
uniset_rwmutex_rlock
l
(
cmutex
);
//#warning Временно отключён кэш
// throw UniSetTypes::NameNotFound();
CacheMap
::
iterator
it
=
mcache
.
find
(
key
(
id
,
node
)
);
CacheMap
::
iterator
it
=
mcache
.
find
(
key
(
id
,
node
)
);
if
(
it
==
mcache
.
end
()
)
if
(
it
==
mcache
.
end
()
)
throw
UniSetTypes
::
NameNotFound
();
throw
UniSetTypes
::
NameNotFound
();
it
->
second
.
timestamp
=
time
(
NULL
);
// фиксируем время последнего обращения
it
->
second
.
ncall
++
;
// т.к. функция возвращает указатель
// т.к. функция возвращает указатель
// и тот кто вызывает отвечает за освобождение памяти
// и тот кто вызывает отвечает за освобождение памяти
...
@@ -1087,15 +1084,16 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
...
@@ -1087,15 +1084,16 @@ ObjectPtr UInterface::CacheOfResolve::resolve( const ObjectId id, const ObjectId
void
UInterface
::
CacheOfResolve
::
cache
(
const
ObjectId
id
,
const
ObjectId
node
,
ObjectVar
ptr
)
const
void
UInterface
::
CacheOfResolve
::
cache
(
const
ObjectId
id
,
const
ObjectId
node
,
ObjectVar
ptr
)
const
{
{
UniSetTypes
::
uniset_rwmutex_wrlock
l
(
cmutex
);
UniSetTypes
::
uniset_rwmutex_wrlock
l
(
cmutex
);
UniSetTypes
::
KeyType
k
(
key
(
id
,
node
));
UniSetTypes
::
KeyType
k
(
key
(
id
,
node
)
);
CacheMap
::
iterator
it
=
mcache
.
find
(
k
);
CacheMap
::
iterator
it
=
mcache
.
find
(
k
);
if
(
it
==
mcache
.
end
()
)
if
(
it
==
mcache
.
end
()
)
mcache
.
insert
(
CacheMap
::
value_type
(
k
,
Info
(
ptr
)));
mcache
.
insert
(
CacheMap
::
value_type
(
k
,
Info
(
ptr
)));
else
else
{
{
it
->
second
.
ptr
=
ptr
;
// CORBA::Object::_duplicate(ptr);
it
->
second
.
ptr
=
ptr
;
// CORBA::Object::_duplicate(ptr);
it
->
second
.
timestamp
=
time
(
NULL
)
;
it
->
second
.
ncall
++
;
}
}
}
}
// ------------------------------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------------------------------
...
@@ -1105,11 +1103,9 @@ bool UInterface::CacheOfResolve::clean()
...
@@ -1105,11 +1103,9 @@ bool UInterface::CacheOfResolve::clean()
uinfo
<<
"UI: clean cache...."
<<
endl
;
uinfo
<<
"UI: clean cache...."
<<
endl
;
time_t
tm
=
time
(
NULL
)
-
CleanTime
*
60
;
// remove_if(mcache.begin(), mcache.end(),OldRef_eq(tm));
for
(
CacheMap
::
iterator
it
=
mcache
.
begin
();
it
!=
mcache
.
end
();)
for
(
CacheMap
::
iterator
it
=
mcache
.
begin
();
it
!=
mcache
.
end
();)
{
{
if
(
it
->
second
.
timestamp
<
tm
)
if
(
it
->
second
.
ncall
<=
minCallCount
)
mcache
.
erase
(
it
++
);
mcache
.
erase
(
it
++
);
else
else
++
it
;
++
it
;
...
@@ -1125,9 +1121,6 @@ bool UInterface::CacheOfResolve::clean()
...
@@ -1125,9 +1121,6 @@ bool UInterface::CacheOfResolve::clean()
void
UInterface
::
CacheOfResolve
::
erase
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
void
UInterface
::
CacheOfResolve
::
erase
(
const
UniSetTypes
::
ObjectId
id
,
const
UniSetTypes
::
ObjectId
node
)
const
{
{
UniSetTypes
::
uniset_rwmutex_wrlock
l
(
cmutex
);
UniSetTypes
::
uniset_rwmutex_wrlock
l
(
cmutex
);
//#warning Временно отключён кэш
// return;
CacheMap
::
iterator
it
=
mcache
.
find
(
key
(
id
,
node
)
);
CacheMap
::
iterator
it
=
mcache
.
find
(
key
(
id
,
node
)
);
if
(
it
!=
mcache
.
end
()
)
if
(
it
!=
mcache
.
end
()
)
mcache
.
erase
(
it
);
mcache
.
erase
(
it
);
...
@@ -1156,7 +1149,7 @@ bool UInterface::isExist( const UniSetTypes::ObjectId id ) const
...
@@ -1156,7 +1149,7 @@ bool UInterface::isExist( const UniSetTypes::ObjectId id ) const
string
nm
=
oind
->
getNameById
(
id
);
string
nm
=
oind
->
getNameById
(
id
);
return
rep
.
isExist
(
nm
);
return
rep
.
isExist
(
nm
);
}
}
catch
(
UniSetTypes
::
Exception
&
ex
)
catch
(
UniSetTypes
::
Exception
&
ex
)
{
{
// uwarn << "UI(isExist): " << ex << endl;
// uwarn << "UI(isExist): " << ex << endl;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment