monitoring and managing computer resource usage on osgi frameworks - ikuo yamasaki, researcher, ntt...

25
Monitoring and Managing Computer Resource Usage on OSGi Frameworks Ikuo YAMASAKI Ikuo YAMASAKI Research Engineer Research Engineer NTT Cyber Solution Laboratories NTT Cyber Solution Laboratories

Upload: mfrancis

Post on 12-Apr-2017

474 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Monitoring and Managing Computer Resource Usage on OSGi Frameworks

Ikuo YAMASAKIIkuo YAMASAKIResearch EngineerResearch Engineer

NTT Cyber Solution LaboratoriesNTT Cyber Solution Laboratories

Page 2: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Background: Background: Service Aggregation PlatformService Aggregation Platform

•• Operation Operation CCenterenter and and Home Service Gateway (HSGW)Home Service Gateway (HSGW) are shared are shared by multiple by multiple Service ProvidersService Providers..

Home ServiceGatewayホームサービ

スオペレーショ

ンセンタOperationCenter

(Portal site)

Focus on service development

OSGi FW

One stop access by users

PCs

AV equipment

White goods

sensorsServ

ice

Prov

ider

s

Platform ProvidersLow initial and running costs for individual service providers.• Cost of operation center and HSGWs

Multiple Service Providers’bundles will be executed.

Page 3: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

BackgroundBackground : resource starvation: resource starvation

OSGi FW

PCs

AV equipment

White goods

sensors

•• In OSGi, In OSGi, bundlebundles create s create threadsthreads–– After After BundleActivator.start(bcBundleActivator.start(bc) returns, threads do their jobs. ) returns, threads do their jobs.

•• ThreadsThreads can deplete computer resources (CPU usage, can deplete computer resources (CPU usage, memory usage) memory usage)

–– Malicious codeMalicious code–– Not intentionally, wrong implementation.Not intentionally, wrong implementation.

•• Especially, resource starvation Especially, resource starvation by different by different Service Service ProviderProviderss’’ bundlesbundles is a big problem.is a big problem.

Page 4: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Our General GoalOur General Goal

•• Develop (Remote)Develop (Remote) Monitoring and Management system of Monitoring and Management system of HSGWHSGW

–– Protect Protect ‘‘goodgood’’ bundles by preventing malicious or misbehaving bundles by preventing malicious or misbehaving bundles on the same FW from depleting resources.bundles on the same FW from depleting resources.

HSGW

ホームサービス

オペレーション

センタOperationCenter OSGi FW

PCs

AV equipment

White goods

sensors

Page 5: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

DesignDesign ConceptConcept

•• LightweightLightweight–– TThehe monitoring & managing system monitoring & managing system adds adds minimal minimal overhead.overhead.–– useuse in service phase,in service phase, not test phasenot test phase..

•• Backwards CompatibilityBackwards Compatibility–– AnyAny bundle that bundle that has been has been written written must be able to must be able to workwork on the on the

systemsystem. . –– Without rewriting source codesWithout rewriting source codes..

•• Independent of specific vendorsIndependent of specific vendors–– Use only standardized measures. Use only standardized measures. –– No specific vendorNo specific vendor’’s OSGis OSGi--FW or JVMFW or JVM. .

Page 6: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Resource Usage to MonitorResource Usage to Monitor

•• ThreadsThreads created by a bundle consume created by a bundle consume –– CPU resourcesCPU resources

•• OurOur Definition:Definition: Sum of CPU usage by all Sum of CPU usage by all threadsthreadscreated by the bundlecreated by the bundle..

–– Memory resourcesMemory resources•• Definition of Definition of ““how much memory a thread and a how much memory a thread and a

bundle is usingbundle is using”” is controversial.is controversial.•• There is no way to monitor it, even in J2SE5.0.There is no way to monitor it, even in J2SE5.0.

Target of this work

Out of scope

Page 7: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

To achieve the goalTo achieve the goal

•• Management Entity Management Entity needs toneeds to1.1. Monitor CPU usage consumed by each bundle.Monitor CPU usage consumed by each bundle.

a.a. Monitor CPU usage of each thread.Monitor CPU usage of each thread.b.b. Manage the relations between bundles and threads, and Manage the relations between bundles and threads, and

Calculate each bundleCalculate each bundle’’s CPU usage.s CPU usage.

2.2. According to the According to the management policymanagement policy adopted, some adopted, some reaction needed.reaction needed.

•• If any bundle consumes too many resources, If any bundle consumes too many resources, •• Take action against excessive bundle, to protect other Take action against excessive bundle, to protect other

bundlesbundles’’ activitiesactivities..

Page 8: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Management Policies (Mgt. Policies)Management Policies (Mgt. Policies)

•• Adaptability to Multiple Adaptability to Multiple mgt. policiesmgt. policies is required. is required. –– Triggers : Triggers : When and Which bundle should be suppressed When and Which bundle should be suppressed

because of its excessive consumption? because of its excessive consumption? •• e.g. e.g.

–– If system CPU usage exceeds 97% for the latest 10 min, the bundlIf system CPU usage exceeds 97% for the latest 10 min, the bundle e consuming the most should be suppressed.consuming the most should be suppressed.

–– A bundle whose CPU usage exceeds 90% for the last 10 min should A bundle whose CPU usage exceeds 90% for the last 10 min should be be suppressed. suppressed.

–– Reactions : Reactions : How to suppress the bundle?How to suppress the bundle?a.a. Change the threadChange the thread’’s prioritys priorityb.b. Kill the threadKill the threadc.c. Stop the bundle ( and kill all the threads created)Stop the bundle ( and kill all the threads created)

–– Activators : Activators : Which entity Which entity triggerstriggers the the reactionreaction??1.1. Entity working on the same host.Entity working on the same host.2.2. Remote monitoring and management entity.Remote monitoring and management entity.

Page 9: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Local Host

OtherProgramsor Bundles

on local

Our System ArchitectureOur System Architecture

1.1. Local entity Local entity –– Automatic reactionAutomatic reaction

•• Owns mgt. policy.Owns mgt. policy.•• Even if the network Even if the network

connection is dead, it works.connection is dead, it works.

OSGi FW

ThreadThreadManagerManager

records

Remote Manager

2.2.Remote entityRemote entity–– Automatic reactionAutomatic reaction

•• Owns mgt. policy.Owns mgt. policy.–– Platform ProviderPlatform Provider’’s s

operatoroperator driven reactiondriven reaction

Bundles

Monitor & Manage locally

JVM

Platform Provider provides(as one of the Managed Agents)

Page 10: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

How to monitorHow to monitor threadthread CPU usage ?CPU usage ?

•• Design ConceptDesign Concept–– LightweightLightweight–– Backward compatibleBackward compatible–– Independent of specific vendorsIndependent of specific vendors

•• JMXJMX of of J2SE5.0J2SE5.0 (used to be called (used to be called ““TigerTiger””) can ) can monitor every thread.monitor every thread.–– Demerit: J2SE5.0 requires high spec machinesDemerit: J2SE5.0 requires high spec machines……

•• Difficult to deploy in embedded systems.Difficult to deploy in embedded systems.

Page 11: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

1.1. Provides Provides standardized measuresstandardized measures to to monitormonitor and and managemanage Java applications.Java applications.

–– Developer can define own Developer can define own MBeanMBean (Managed Bean(Managed Bean))•• Getter / setter styleGetter / setter style

–– JMX Agent (JMX Agent (MBeanMBean ServerServer) enables management of target ) enables management of target object through registered object through registered MBeanMBean

JMX (Java Management JMX (Java Management eXtentioneXtention))

JVM (S2SE5.0)

Application

MBean Server (JMX Agent)

MBean

Managed object

MBean

Instrumentation Level

Agent Level

Remote Management Level

Page 12: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

2.2. Resources can be monitored and managed, either Resources can be monitored and managed, either remotelyremotely or or locallylocally..

–– Protocol is replaceable.Protocol is replaceable.•• RMI connector RMI connector uses Java RMI.uses Java RMI.

JMX (Java Management JMX (Java Management eXtentioneXtention))

JVM (S2SE5.0)

MBean Server

MBean MBean

Instrumentation Level

Agent Level

Remote Management Level

Protocol Adapter Protocol Adapter Connector

Web Browsers

HTTP

SNMP Mgt. App.

SNMP

JMX-compliantMgt, App.

JMX Remote Protocol

Page 13: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

3.3. Platform Platform MBeanMBean Server (Server (MXBeanMXBean Server) Server) is built in is built in JVMJVM–– Several types of Several types of MXBeanMXBeanss are defined in the spec.are defined in the spec.

•• Every thread can be monitored and managed through Every thread can be monitored and managed through ThreadThreadMXBeanMXBean

–– including including CPU usageCPU usage

–– MXBeansMXBeans are registered automatically.are registered automatically.

JMX (Java Management JMX (Java Management eXtentioneXtention) )

Application

MXBean Server

ThreadMXBean

Connector JMX-compliantMgt, App.

JMX Remote Protocol

Thread

JMX is lightweight

Page 14: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

How to monitor How to monitor bundlebundle CPU usage ?CPU usage ?

•• We define We define BundleBundle--ThreadThread--Tree (BTT)Tree (BTT)–– in order for in order for Thread ManagerThread Manager to maintain to maintain the the relationsrelations between between

every threadevery thread and and its creating bundleits creating bundle•• At the creation of a thread, At the creation of a thread, •• pair of thepair of the threadthread and and its creating bundleits creating bundle must be reported to the must be reported to the

Thread ManagerThread Manager..

•• If rewriting codes is acceptable, no problem.If rewriting codes is acceptable, no problem.•• But our But our Design Concept: Backward compatibilityDesign Concept: Backward compatibility

–– No codes rewriting permitted.No codes rewriting permitted.

FW’s bundle starting Thread

Thread D

Thread A

Thread C

Bundle 1

Thread E

Thread B Bundle 2

Page 15: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Byte Code Weaving: AOP (Byte Code Weaving: AOP (AspectJAspectJ))

•• We adopt We adopt Byte Code WeavingByte Code Weaving..–– AOP (Aspect Oriented Programming)AOP (Aspect Oriented Programming): : AspectJAspectJ

•• ““WeaveWeave”” : AOP allows us to insert : AOP allows us to insert adviceadvicebefore/after/aroundbefore/after/around pointcutpointcut in the byte code.in the byte code.

–– AdviceAdvice : byte code to be woven: byte code to be woven–– PointcutPointcut : where to weave the byte code.: where to weave the byte code.–– E.g. E.g. Insert the specified codeInsert the specified code at the beginning / end of the at the beginning / end of the

specified method of the specified class.specified method of the specified class.

•• Byte codeByte code can be altered evencan be altered even without source codewithout source code of the of the program.program.

Page 16: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Offline procedures

Offline Bundle WeavingOffline Bundle Weaving

JAR of Bundle A Weaving

(Aspect file:ThreadAspect.aj )

1.1. Service ProviderService Provider ((SPSP) passes its bundle JAR to ) passes its bundle JAR to Platform ProviderPlatform Provider (without source code).(without source code).

2.2. Platform ProviderPlatform Provider weaves the aspects into the bundle weaves the aspects into the bundle and posts it on the web server.and posts it on the web server.

3.3. OSGiOSGi--FWsFWs of HSGW will install the woven bundle from of HSGW will install the woven bundle from the web server.the web server.

Will be Installedon Users’ FW

at BundleContext.installBundle(uri)

ThreadAspect.class will be created.

Woven Jar of Bundle A

SP passes JAR

Page 17: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Aspect to Weave into bundles 1Aspect to Weave into bundles 1

• Pointcut 1: Before a bundle is started• Advice Inserted: set its bundle object into the field

variable “bundle” in ThreadAspect class.

public class Activator implements BundleActivator {public void start(BundleContext bc) throws Ex {

Bundle bundle = bc.getBundle();ThreadAspect.getInstance().setBundle(bundle);System.out.println(“OSGi: Bundle started”);...

}...

} Pseudo woven code

Page 18: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Aspect to Weave into bundles 2Aspect to Weave into bundles 2

• Pointcut 2: Before a thread is started• Advice Inserted:

– A) retrieve its bundle object from the field variable “bundle” in ThreadAspect class, and

– B) notify the relation between the thread and bundle creating itto ThreadManager.

public class ThreadCreate {public void doTask() {

Thread t = new Thread(new Runnable() {public void run() {...;}

});Bundle bundle = ThreadAspect.getInstance().getBundle();ThreadManager tm = ThreadManager.getInstance();tm.addThread(t, bundle);t.start();

}} Pseudo woven code

Page 19: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

OSGi FW

MXBean Server

Operation of the SystemOperation of the System

Thread ManagerBundle

Bundle

1. Install woven bundle

2. BundleEvent is delivered to Synchronous Bundle Listener impl.

3. construct Bundle-Thread-Tree(BTT) BTT

Page 20: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

OSGi FW

MXBean Server

Operation of the SystemOperation of the System

Thread ManagerBundle 4. Bundle is started

ThreadAspectbundle

5. Store Bundle object

Page 21: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

OSGi FW

MXBean Server

Operation of the SystemOperation of the System

Thread ManagerBundle 6. When a thread is created

ThreadAspectbundle

7. Retrieve BundleThread

8. Send them to Thread Manager

BTT

9. Update Bundle-Thread-Tree

Thread A

Page 22: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

OSGi FW

MXBean Server

Operation of the SystemOperation of the System

Thread ManagerBundle

Threads

Thread Manager monitors every thread’s CPU usage periodically, and records it locally.

Thread A

Thread B

BTT

ThreadMXBean

ASample Thread SleepB

records

Page 23: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

OSGi FW

MXBean Server

ThreadManagerMBeanThreadManagerMBean

Thread Manager

Threads

Thread Manager registers its own MBean “ThreadManagerMBean”, which provides IF of

1.Monitoring recorded data.2.Suppressing actions taken

against bundles and threads.

Thread A

Thread B

Bundle

ThreadMXBean

A B records

ThreadManager-MBean

Connector JMX-compliantMgt, App.

JMX Remote Protocol

Page 24: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

Local Host

Otherprogramsor bundles

on local

No restrictions on Mgt. PoliciesNo restrictions on Mgt. Policies

OSGi FW

MXBean Server

Thread Manager

Thread A

Thread B

Bundle

ThreadMXBean

A B

records

JMX-compliantMgt, App.

ThreadManager-MBean

Connector

•• Diverse Diverse mgt. policiesmgt. policies can be supportedcan be supported–– Triggers Triggers –– Reactions Reactions –– ActivatorsActivators

Either is possible.

Page 25: Monitoring and Managing Computer Resource Usage on OSGi Frameworks - Ikuo Yamasaki, Researcher, NTT Cyber Solutions Laboratories

SummarySummary

•• Background:Background:–– Threads created by bundle can deplete computer resources.Threads created by bundle can deplete computer resources.–– Monitoring and management system is required, especially in Monitoring and management system is required, especially in

Service Aggregation Platform.Service Aggregation Platform.•• Proposal:Proposal:

–– CPU usage management system on OSGi FW adoptingCPU usage management system on OSGi FW adopting•• JMX in J2SE5.0JMX in J2SE5.0

–– LightweightLightweight–– Independent of specific vendorsIndependent of specific vendors

•• AOP (AOP (AspectJAspectJ))–– No rewrites of existing code neededNo rewrites of existing code needed

–– Proposed architecture can support diverse management policiesProposed architecture can support diverse management policies•• Trigger decisionTrigger decision•• Reactions to suppress the bundle and threads.Reactions to suppress the bundle and threads.•• Activators (remotely and locally)Activators (remotely and locally)