Web Cache Prefetching as an Aspect: Towards a Dynamic-Weaving Based Solution Marc Ségura-Devillechaise, Jean-Marc Menaud, Gilles Muller OBASCO Project EMN/INRIA, France Julia L.

Download Report

Transcript Web Cache Prefetching as an Aspect: Towards a Dynamic-Weaving Based Solution Marc Ségura-Devillechaise, Jean-Marc Menaud, Gilles Muller OBASCO Project EMN/INRIA, France Julia L.

Web Cache Prefetching as an Aspect:
Towards a Dynamic-Weaving Based
Solution
Marc Ségura-Devillechaise, Jean-Marc Menaud, Gilles Muller
OBASCO Project EMN/INRIA, France
Julia L. Lawall
DIKU University of Copenhagen, Denmark
AOSD 2003
Improving the Web
Web cache:
• Stores previously-accessed contents preparing for
later potential re-accesses
• Advantageous if contents are accessed repeatedly
Content prefetching:
• Stores contents that have not yet been accessed
preparing for later potential accesses
• Advantageous if contents are accessed eventually
– Relies on the prediction of the access patterns of a Web
application
2
Prefetching
• A prefetching policy must anticipate access
patterns:
– Access patterns are application dependent
– A Web cache is shared among many Web applications
• Consequence:
– Policies should be deployed on demand in the cache
• Problem:
– How to integrate dynamically new prefetching policies
within Web caches?
3
Web Caches
Cache in the neighborhood
9
55
3
8
4
3?
Storage space
8
45
Storage space
3?
3?
3
2
3
Cache
Client
client
request
cooperation
request
4
11
8
89 5
2
45
3
3
3?
Storage space
3
Server
3
6
3
Storage space
Cache in the neighborhood
4
Web cache
Accept user request
Request analysis
Accept cooperation request
Client Cache
File
lookup
Send cooperation
request
Server
Send cooperation reply
Local Storage
Send Internet request
Network module
Network
neighborhood
Replacement policy
Internet
Send User Reply
Typical flow of a user request
Typical flow of a cooperation request
5
Issues in integrating prefetching
in Web caches
• Observation:
– Prefetching crosscuts the cache structure
– Execution paths: modules are not sufficient
• A “natural” solution: AOP
6
AOP for prefetching in Web Caches
Mapping
• Joinpoints
Specifies where adaptation can take place
Where, within the cache, a policy is allowed to run
• The pointcut language
Specifies when to adapt
When a particular prefetching policy should be triggered
• Advice language
Specifies the behaviour of the adaptation code
What the prefetching policy should do
• Weaving
Link the adaptation code to the base program
Link a prefetching policy to the cache 7
AOP for prefetching in Web caches
Steps
Base program development
Web cache development
Adapted development
Execution of base program
Web cache execution
Adapted execution
Weaving time
Prefetching deployment time
Adaptation code link time
Aspect development
Prefetching policy
Adaptation code
time
8
Constraints on the runtime system
• A cache processes every request to a subnet.
– It must be efficient.
The aspect code must be efficient.
– The cache service must always be available.
The base program must continuously run.
• Web caches are written in C.
The aspect system must support the C language.
• Prefetching policies should be deployed on demand
in the cache.
The aspect system must allow dynamic weaving.
9
Meeting the constraints
µDyner runtime system
• Strong performance requirements
– Base program code preparation (hookable)
– Aspect and base program
• Translated into C code by our tools
• Can be compiled with compiler optimizations
– Weaving is performed with almost no interruption of the
application
• Targeted for an audience of C developers
– Advice as C code block
– All pointcuts can be thought as « did the base program
execute this C construct ?»
• Need to be able to perform the extension dynamically
– Weaving performed at runtime
10
Meeting the constraints
µDyner language
• Need to be able to reason on execution paths
– Pointcut on nested functions calls «did f() call g()call
h()?»
• Need to be able to monitor some global variable
– Last element in the pointcut sequence can test whether a
given global variable has been read or written
• In order to extend Web caches
– The advice replaces the execution of the last element in the
sequence.
• Can trigger execution of the original definition through continue.
11
Runtime
Build and design time
Lifecycle and tools support
Base
Aspect
program
development
development
Execution
Weaving
12
Runtime
Build and design time
Lifecycle and tools support
Cache source code
C with hookable
Preprocessing
Pretreated base code
µDyner support library
Compile - link
development
(gcc)
Postprocessing
Adaptable cache
Aspect
Base code
maintainer
Execution
hookable int withdraw(float amount,BankAccount * account) {
assert(account!=NULL);
Weaving
account->debit = amount
+ account->debit ;
return SUCCESS;
}
13
Build and design time
Lifecycle and tools support
Prefetching policies: aspect
sources
Cache source code
C with hookable
Pretreatment
Pretreated base code
Preprocessing
µDyner support library
C code
Pointcut action as functions
Runtime
#include "../BaseProgram/BankAccount.h"
Compile - link
Compile
#define MAX_WITHDRAWAL_AMOUNT
1000.0
(gcc)
link
Postprocessing
anAspect:[
(gcc)
aspects
int withdraw(float
amount, BankAccount Compiled
* account)
:[
Adaptable cache
Base code Aspect
Shared library
{
maintainer developer
if(amount >= MAX_WITHDRAWAL_AMOUNT)
Execution
return BANK_REFUSED;
return continue_withdraw(amount,account);
Weaving
}
]
]
14
Runtime
Build and design time
Lifecycle and tools support
Prefetching policies: aspect
sources
Cache source code
C with hookable
Preprocessing
Pretreated base code
Preprocessing
µDyner support library
Compile - link
Compile
link
(gcc)
(gcc)
Postprocessing
Adaptable cache
Execute
C code
Pointcut action as functions
Base code Aspect
maintainer developer
Compiled aspects
Shared library
Cache administrator
Cache (host process)
Cache threads
µDyner instrumentation
thread
15
Runtime
Build and design time
Lifecycle and tools support
Prefetching policies: aspect
sources
Cache source code
C with hookable
Preprocessing
Pretreated base code
Preprocessing
µDyner support library
Compile - link
Compile
link
(gcc)
(gcc)
Postprocessing
Adaptable cache
Execute
Base code Aspect
maintainer developer
Compiled aspects
Shared library
Cache administrator
Cache (host process)
Cache threads
C code
Pointcut action as functions
µDyner instrumentation
thread
Prefetching policy deployed through
shell commands (weave - deweave)
16
µDyner implementation
• Aspect as shared library
• Base program preparation
• Weave
17
µDyner compiled
aspects
Shared native library
18
µDyner compiled
aspects
advice code
aspect entry point
continue pointers
19
µDyner compiled
aspects
advice code
aspect entry point
continue pointers
Points to an address in the base program allowing
to execute the last pointcut element
20
µDyner compiled
aspects
Invoked each time
the base program
reaches the last
joinpoint element
advice code
aspect entry point
continue pointers
21
µDyner compiled
aspects
Invoked each time
the base program
reaches the last
join point element
advice code
aspect entry point
Checks pointcut
Calls advice or
continue
continue pointers
22
µDyner base code
preparation
• Prepare the base program for analysis
– Collect functions and variables addresses
– Collect addresses of instructions accessing
hookable variable
– Collect addresses of instructions calling functions
• Prepare the base program for alteration
– Make potential rewriting sites big enough to contain
a jump instruction
23
µDyner weaver
• Open the aspect shared library
• Overwrite the last joinpoint as a jump to the
aspect entry point
• Set the continue pointers in the aspect library
24
Weaving implementation
int withdraw(float amount,
BankAccount * account) {
JUMP +3; NOP; NOP; NOP;
// original function code
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
25
Weaving implementation
Overview of a compiled aspect
continue pointer
int withdraw(float amount,
BankAccount * account) {
JUMP +3; NOP; NO; NOP;
// original function code
void * continue_withdraw = withdraw +5;
int anAspect(float amount,
BankAccount * account) {
#include
"../BaseProgram/BankAccount.h"
if(pointcut != TRUE)
aspect entry point
#define MAX_WITHDRAWAL_AMOUNT
1000.0
continue_withdraw(amount,account);
anAspect:[
else
rewriting
site
int withdraw(float amount,
advice(amount,account);
}BankAccount * account) :[
{
if(amount
>= MAX_WITHDRAWAL_AMOUNT)
int advice(float amount,
return BANK_REFUSED;
BankAccount * account) {
return continue_withdraw(amount,
if(amount >=
account);
MAX_WITHDRAWAL_AMOUNT)
}
aspect
advice
}
int transfer_money {
]
// code
]
withdraw(100,account)
}
return BANK_REFUSED;
return
continue_withdraw(amount,account);
Host process
Aspect
}
Aspect
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 26
Weaving implementation
1 load the aspect library – allocate the hook
2 rewriting the base code
void * continue_withdraw = withdraw +5;
3 set aspect_loaded to true
Hook:
if(aspect_loaded
==TRUE)
JUMP anAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP +3; NOP; NO; NOP;
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account)
{
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
Aspect
continue_withdraw(amount,account);
}
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
Hook
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 27
Weaving implementation
1 load the aspect librairy – allocate the hook
2 rewriting the base code
void * continue_withdraw = withdraw +5;
3 set aspect_loaded to true
Hook:
if(aspect_loaded
==TRUE)
JUMP anAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP
JMP 3;Hook
NOP; NOP; NOP;
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account) {
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
Aspect
}
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
Hook
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 28
Weaving implementation
1 load the aspect librairy – allocate the hook
2 rewriting the base code
void * continue_withdraw = withdraw +5;
3 set aspect_loaded to true
Hook:
if(aspect_loaded
==TRUE)
JUMP anAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP Hook
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account) {
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
}
Aspect
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
Hook
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 29
Weaving implementation
Use case – advice execution
void * continue_withdraw = withdraw +5;
Hook:
if(aspect_loaded
==TRUE)
JUMP anAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP Hook
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account) {
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
Aspect
}
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
Hook
Function return
Function call
Jump
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 30
Weaving implementation
Use case – advice execution
void * continue_withdraw = withdraw +5;
Hook:
if(aspect_loaded
==TRUE)
JUMP unAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP Hook
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account) {
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
}
}
int transfer_money {
// code
Aspect
withdraw(100,account)
}
Host process
Hook
Function return
Function call
Jump
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 31
Link performance evaluation
Methods
• Micro evaluation :
Invoke an empty method
Invoke an empty method with an empty aspect
The ratio gives a performance evaluation
• Macro evaluation :
Measure the runtime of a given application for a given input
Same measure with the same application with the same input but
with woven aspects
The ratio gives a performance evaluation
32
Link performance evaluation
Results
• Linux Pentium4 1.6 GHz
• Micro evaluation:
2.2 slower
• Macro evaluation:
counting aspect)
1.015 slower (Tinyproxy – hit
33
Related Work
Dynamic weaving:
– PROSE Popovici A., Gross T., Alonso G.
2002
– JAC Pawlak R., Seinturier L., Duchien 2001
Native code instrumentation:
– Dyninst Buck B., Hollingsworth J.K, 2000
AOP for C:
– AspectC Y. Coady, G. Kiczales 2001
34
Future Work
• Increase the expressivity of the pointcut language
(designing static functions…)
• Remove all static preparation of the base program code
– Implies: suppression of hookable
– Exploit debugging information rather than relying on source code
• Design a set of prefetching policies
• Modify Squid (prepare it for aspectization)
– Build a dynamically adaptable web cache
– Experiment with prefetching policies
35
Conclusion
• Prefetching as a crosscutting concern
• A method to link the base program to the
aspect
• Almost no service interruption during weaving
• Very fast, once woven
• Prototype: µDyner
– Within the implementation, links aspect and
base program through dynamic code rewriting
– Running under GNU/Linux, Pentium
36
Questions
References
[BUC 00] BUCK B., Hollingsworth J. K., An API for Runtime Code Patching , The
International Journal of High Performance Computing Applications, vol. 14, n 4, 2000, p.
317-329.
[CAH 02] Redmond B., Cahill V., Supporting unanticipated dynamic adaptation of application
behaviour ECOOP 2002 – Object-Oriented Conference, 16th European Conference, vol.
2374 of Lectures Notes in Computer Sciences page 205-230, Malaga, Spain Juin 2002
[DOU 01] Douence R., Motelet O., Südholt M., A formal definition of crosscuts, Proceedings
of the 3rd International Conference on Reflection and Crosscutting Concerns, vol. 2192
de Lecture Notes in Computer Science, Kyoto, Japan, 2001, Springer Verlag, p. 170-186.
[DOU 02] Douence R., Fradet P., Südholt M., A framework for the detection and resolution of
aspect interactions , Proceedings of the ACM SIGPLAN/SIGSOFT Conference on
Generative Programming and Component Engineering (GPCE’02), 2002, p. 173-188.
[KLE 96] Kleinoder J., Golm M. MetaJava : An efficient run-time meta architecture for Java.
International Workshop on Object-Orientation In Operation Systems – IWOOS’96, p. 5461, Seattle WA, octobre 1996.
[HOL 97] Hollingsworth J. K., Miller B. P., Goncalves M. J. R., Naim O., Xu Z., Zheng L., MDL
: A Language and Compiler for Dynamic Program Instrumentation, IEEE PACT, 1997, p.
201-213.
[OLI 98] Oliva A., Buzato L.E. The implementation of Guaranà in Java. Techhnical report IC98-32, Institute of of computing, University of Campinas, Brésil, septembre 1998.
[PAW 01] Pawlak R., Seinturier L., Duchien L., Florin G., JAC : A Flexible Solution for AspectOriented Programming in Java , Proceedings of Reflection’01, vol. 2192 de Lecture Notes
in Computer Science, Springer, 2001, p. 1-24.
[POP 02] Popovici A., Gross T., Alonso G., Dynamic weaving for aspect-oriented
programming , Proceedings of the 1st international conference on Aspect-oriented
software development, Enschede, The Netherlands, 2002, ACM Press, p. 141-147.
38
AOP in a nutshell
• Joinpoints
– The instrumentation sites within the base program.
• The pointcut language
– A pattern on the execution trace of the base program.
• Action language
– What to do when the pointcut matches the execution of
the base program
• Weaving
– Link a base program and an aspect
– At compile time, at load time, at runtime.
39
#include "../BaseProgram/BankAccount.h"
#define MAX_WITHDRAWAL_AMOUNT 1000.0
int (*continue_withdraw)(float amount,BankAccount * account)=NULL;
int advice(float amount,BankAccount * account){
if(amount >= MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
Prefetching policies: aspect
Cache source code
return
continue_withdraw(amount,account);
sources
C with hookable
}
Pretreatment
int anAspect(float amount,BankAccount * account)Pretreatment
{
C code
return
advice(amount,account);
Pretreated base
code
µDyner support library
Pointcut action as functions
}
Compile - link
Runtime
Build and design time
Three actors for three steps
Compile
link
(gcc)
(gcc)
Postreatement
Adaptable cache
Execute
Base code Aspect
maintainer developer
Cache administrator
Cache (host process)
Cache threads
Compiled aspects
Shared library
µDyner instrumentation
thread
Prefetching policy deployed through
shell commands (weave - deweave)
40
Build and design time
Three actors for three steps
Prefetching policies: aspect
sources
Cache source code
C with hookable
Pretreatmentt
Pretreated base code
Pretreatment
µDyner support library
C code
Pointcut action as functions
Runtime
Compile - link
Compile
int withdraw(float
amount,BankAccount * account)
(gcc)
link
Postreatement __attribute__ ((noinline));
(gcc)
int withdraw(float amount,BankAccount * account)
Compiled {
aspects
Adaptable cache
Base code Aspect
Shared library
__asm__ __volatile__ ( "jmp assert");
maintainer developer
__asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop");
Cache administrator
Execute
__asm__ __volatile__
("nop");
Cache (host process)
assert(account!=NULL);
Prefetching policy deployed through
µDyner instrumentation
Cache threads
if((account->credit)
<=thread
OVERDRAFT_WITH_TRIAL)
shell commands (weave - deweave)
return BANK_REFUSED;
account->debit = amount +account->debit ;
return SUCCESS;
}
41
By Partial match
By Popularity
By Lifetime
Interaction
Interface appropriate
Interaction
Interface inadequate
No interaction
Accept user request
Parse request
File lookup
Local storage
Accept ICP request
Send Internet request
Send ICP request
Send user reply
Send ICP reply
Replacement policy
42
Summary
• Difficult to anticipate the interaction of
prefetching and the cache
– Interaction depends heavily of the policy
– Difficult for the cache to offer an API
supporting this interaction
• A generic API might even slow down the
cache.
43
Link performance evaluation
• Micro evaluation :
ratio
–
–
–
–
–
µDyner (AOP for C – dynamic native code rewriting ) :
IguanaJ [CAH 02] (MOP for Java – dynamic code rewriting of JIT code) :
MetaXa [KLE 96] (MOP for Java – modified JVM) :
Prose [POP 02] (AOP for Java – based on Java debugging API ) :
Guaranà [OLI 98] (MOP for Java - modified JVM modifiée) :
2.2
24.0
28.0
40.0
70.0
• Macro evaluation :
ratio
– µDyner (AOP for C) with Tinyproxy :
– Java Aspect Component [PAW 01] (AOP for Java) :
1.015
5.000
44
The EAOP model [DOU 01, DOU 02]
• Joinpoint
– an event embeds a partial description of the current
execution context
• events are grouped in a single execution trace
• Pointcut
– a sequence of events
– a monitor inspects the trace
• continuously checks the different pointcuts
• triggers the execution of aspect when needed
• The action language
– access to the base program through the information
contained in the events
• Weaving
– Registration on the monitor
45
EAOP for Web Caches?
Well defined semantics but…
• Issues with the model
– Not very well suited for concurrent applications
– The duplication of execution context is relatively costly.
Events are big.
• Issues with the proposed prototype
– Weaving for Java
– The set of events are open
Everybody can use his own events
Lack of a clear distinction between action and pointcut
46
Weaving implementation
Use case – pointcut not verified
void * continue_withdraw = withdraw +5;
Hook:
if(aspect_loaded
==TRUE)
JMP anAspect
} else {
int withdraw(float amount,
BankAccount * account) {
JUMP Hook
// original function code
JUMP withdraw+5
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
}
}
int advice(float amount,
BankAccount * account) {
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
}
Aspect
}
int transfer_money {
// code
withdraw(100,account)
}
Host process
Hook
Function return
Function call
Jump
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 47
Weaving implementation
Use case – aspect not activated
void * continue_withdraw = withdraw +5;
int withdraw(float amount,
BankAccount * account) {
JUMP Hook
// original function code
JUMP withdraw+5
}
int transfer_money {
// code
withdraw(100,account)
Host process
}
int advice(float amount,
BankAccount * account)
{
if(amount >=
MAX_WITHDRAWAL_AMOUNT)
return BANK_REFUSED;
return
continue_withdraw(amount,account);
Aspect
}
}
}
int anAspect(float amount,
BankAccount * account) {
if(pointcut != TRUE)
continue_withdraw(amount,account);
else
advice(amount,account);
Hook:
if(aspect_loaded
==TRUE)
JMP anAspect
} else {
Hook
Function return
Function call
Jump
Generated at compilation of the
base program
Generated at compilation of the
aspect
Generated at weaving time 48