Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
徐少华
midjourney-proxy
Commits
82a53d5a
Commit
82a53d5a
authored
Oct 09, 2020
by
胡青青
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:[none]添加热点key采集日志,增长快类型key日志
parent
5b201992
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
106 deletions
+92
-106
JedisClusterAspect.java
...ava/com/pcloud/common/core/aspect/JedisClusterAspect.java
+0
-0
LFU.java
...core/src/main/java/com/pcloud/common/core/aspect/LFU.java
+92
-0
ParamLogAspect.java
...in/java/com/pcloud/common/core/aspect/ParamLogAspect.java
+0
-106
No files found.
pcloud-common-core/src/main/java/com/pcloud/common/core/aspect/JedisClusterAspect.java
View file @
82a53d5a
This diff is collapsed.
Click to expand it.
pcloud-common-core/src/main/java/com/pcloud/common/core/aspect/LFU.java
0 → 100644
View file @
82a53d5a
package
com
.
pcloud
.
common
.
core
.
aspect
;
import
java.util.Collections
;
import
java.util.Map
;
import
java.util.concurrent.ConcurrentHashMap
;
public
class
LFU
<
K
,
V
>
{
private
final
int
capcity
;
private
Map
<
K
,
V
>
cache
=
new
ConcurrentHashMap
<>();
private
Map
<
K
,
HitRate
>
count
=
new
ConcurrentHashMap
<>();
public
LFU
(
int
capcity
)
{
this
.
capcity
=
capcity
;
}
public
Map
<
K
,
HitRate
>
getHotKeyMap
()
{
Map
<
K
,
HitRate
>
count
=
this
.
count
;
return
count
;
}
public
void
put
(
K
key
,
V
value
)
{
V
v
=
cache
.
get
(
key
);
if
(
v
==
null
)
{
if
(
cache
.
size
()
==
capcity
)
{
removeElement
();
}
count
.
put
(
key
,
new
HitRate
(
key
,
1
,
System
.
nanoTime
(),
value
));
}
else
{
addHitCount
(
key
);
}
cache
.
put
(
key
,
value
);
}
public
V
get
(
K
key
)
{
V
value
=
cache
.
get
(
key
);
if
(
value
!=
null
)
{
addHitCount
(
key
);
return
value
;
}
return
null
;
}
//移除元素
private
void
removeElement
()
{
HitRate
hr
=
Collections
.
min
(
count
.
values
());
cache
.
remove
(
hr
.
key
);
count
.
remove
(
hr
.
key
);
}
//更新访问元素状态
private
void
addHitCount
(
K
key
)
{
HitRate
hitRate
=
count
.
get
(
key
);
hitRate
.
hitCount
=
hitRate
.
hitCount
+
1
;
hitRate
.
lastTime
=
System
.
nanoTime
();
}
//内部类
class
HitRate
implements
Comparable
<
HitRate
>
{
private
K
key
;
private
V
v
;
private
int
hitCount
;
private
long
lastTime
;
private
HitRate
(
K
key
,
int
hitCount
,
long
lastTime
,
V
v
)
{
this
.
key
=
key
;
this
.
hitCount
=
hitCount
;
this
.
lastTime
=
lastTime
;
this
.
v
=
v
;
}
@Override
public
int
compareTo
(
HitRate
o
)
{
int
compare
=
Integer
.
compare
(
this
.
hitCount
,
o
.
hitCount
);
return
compare
==
0
?
Long
.
compare
(
this
.
lastTime
,
o
.
lastTime
)
:
compare
;
}
public
K
getKey
()
{
return
key
;
}
public
V
getV
()
{
return
v
;
}
public
int
getHitCount
()
{
return
hitCount
;
}
}
}
pcloud-common-core/src/main/java/com/pcloud/common/core/aspect/ParamLogAspect.java
deleted
100644 → 0
View file @
5b201992
/**
*
*/
package
com
.
pcloud
.
common
.
core
.
aspect
;
import
java.lang.reflect.Method
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.context.annotation.Configuration
;
import
com.alibaba.fastjson.JSON
;
import
com.pcloud.common.utils.string.StringUtil
;
/**
* @author:songx
* @date:2018年4月26日,下午2:32:36
*/
@Aspect
@Configuration
public
class
ParamLogAspect
{
/**
*
*/
private
final
static
Logger
LOGGER
=
LoggerFactory
.
getLogger
(
""
);
@Pointcut
(
"execution(* com.pcloud..*(..))"
)
public
void
bizPoint
()
{
}
/**
* 方法执行前以后执行
*
* @param joinPoint
*/
@Before
(
"bizPoint()"
)
public
void
doBefore
(
JoinPoint
joinPoint
)
{
ParamLog
paramLog
=
checkAnnotation
(
joinPoint
);
if
(
paramLog
==
null
)
{
return
;
}
Signature
signature
=
joinPoint
.
getSignature
();
String
methodName
=
signature
.
getName
();
String
description
=
paramLog
.
description
();
description
=
StringUtil
.
isEmpty
(
description
)
?
paramLog
.
value
()
:
description
;
StringBuffer
msg
=
new
StringBuffer
(
signature
.
getDeclaringTypeName
()).
append
(
" 【"
+
methodName
+
" before】"
);
if
(!
StringUtil
.
isEmpty
(
description
))
{
msg
.
append
(
description
);
}
if
(!
paramLog
.
isBefore
())
{
LOGGER
.
info
(
msg
.
toString
());
}
else
{
String
argsJson
=
JSON
.
toJSONString
(
joinPoint
.
getArgs
());
LOGGER
.
info
(
msg
.
append
(
",[Args]="
).
append
(
argsJson
).
toString
());
}
}
/**
* 方法执行完以后执行
*
* @param joinPoint
* @param result
*/
@AfterReturning
(
pointcut
=
"bizPoint()"
,
returning
=
"result"
)
public
void
doAfterReturn
(
JoinPoint
joinPoint
,
Object
result
)
{
ParamLog
paramLog
=
checkAnnotation
(
joinPoint
);
if
(
paramLog
==
null
)
{
return
;
}
Signature
signature
=
joinPoint
.
getSignature
();
String
methodName
=
signature
.
getName
();
String
description
=
paramLog
.
description
();
description
=
StringUtil
.
isEmpty
(
description
)
?
paramLog
.
value
()
:
description
;
StringBuffer
msg
=
new
StringBuffer
(
signature
.
getDeclaringTypeName
())
.
append
(
" 【"
+
methodName
+
" afterReturn】"
);
if
(!
StringUtil
.
isEmpty
(
description
))
{
msg
.
append
(
description
);
}
if
(!
paramLog
.
isAfterReturn
())
{
LOGGER
.
info
(
msg
.
toString
());
}
else
{
String
resultJson
=
JSON
.
toJSONString
(
result
);
LOGGER
.
info
(
msg
.
append
(
",[result]="
).
append
(
resultJson
).
toString
());
}
}
private
static
ParamLog
checkAnnotation
(
JoinPoint
joinPoint
)
{
// 获取方法签名
MethodSignature
signature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
// java reflect相关类,通过反射得到注解
Method
method
=
signature
.
getMethod
();
if
(!
method
.
isAnnotationPresent
(
ParamLog
.
class
))
{
return
null
;
}
return
method
.
getAnnotation
(
ParamLog
.
class
);
}
}
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