Thread Management in Application Servers

quicksandwalleyeInternet και Εφαρμογές Web

31 Οκτ 2013 (πριν από 3 χρόνια και 5 μήνες)

60 εμφανίσεις

0

0

Thread Management
in Application Servers

Wednesday, October 11, 2006


Nicolas

DOLET

(nicolas.dolet@inria.fr)

Philippe

MERLE

(
philippe.merle@inria.fr
)

Jacquard Project
-

INRIA Futurs,

Laboratoire d‘Informatique Fondamentale de Lille (LIFL),

Université des Sciences et Technologies de Lille (USTL),

Villeneuve d’Ascq, France

RNTL JOnES Meeting


Paris
-

France

1

1

Outline



Context



Problem & Motivation



Objectives


Control threading activity



Our approach


Thead Management Framework (TMF)


Area Management Framework (AMF)



Framework organization



Conclusion



Perspectives

2

2

Context



Application servers host Application Components
(AC)
:


OSGi:


Bundles



JOnAS:


EJBs


Servlets



PEtALS:


JBI Binding Components


JBI Service Components

3

3

Context



Application servers are composed of Middleware Components
(MC)
:



JOnAS =
Web and EJB containers for application components


+ ( JacORB & Axis & JORAM for communication )


+ ( JORM & JOTM/MEDOR/Speedo & C
-
JDBC for services )


+ …




PEtALS = Enterprise Service Bus (ESB), JBI compliant





+ JBI containers





+ JORAM for communication


4

4

Context

MC2


AC1


AC3


hosted by

composed of

AC2


MC3


MC1


Application Server



Both AC & MC components can create Threads !

5

5

Problem & Motivation



Problem:


Creation of a large number of threads can cause:


Performance degradation due to thread context switches


Partial crash of the JVM / Application Server




Motivation: need to control Thread allocation


Ensure the property:



“Never more than X threads simultaneously”



6

6

Objectives



Monitor Thread allocation...


of (embedded) Middleware Components


of (user) Application Components



... with several statistics:


Number of active threads


History of threads allocation


List of classes using threads



Protecting Application Servers


against MC (
e.g.

JMS could create too many threads)


Thread pool solution drawback:






MC thread pools
>

JVM Threads limit


against AC (
e.g.

EJB should not create threads)


There is currently no solution for the control of AC threading activity


Future public Application Server could be hacked by a viral AC

7

7

Middleware Components Integration


The Pool Solution’s Drawbacks

Application Server

configures

(in a property file)

configures

(via JMX)

MC1

Configurable

Thread Pool



Thread

how to

configure ?

MC2

Configurable

Thread Control



Thread

MCn

Thread

Management ?



Thread



Developpers have to implement the thread control for each new component...

8

8

Thread Management Framework with APIs

Thread Management Framework

MC2

Explicit Thread

Management

AC

No Thread

Management

MC1

Configurable

Thread Management

MC2

Configurable

Thread Management





Modify all MC for using TMF APIs


Manual patches of source code of existing components


Using Aspect Oriented Programming to modify existing components

uses

uses

uses

9

9

Thread Management Framework

TMF with the Thread Class Adaptation

AC

No Thread

Management

MC1

Configurable

Thread Management

MC2

Configurable

Thread Management

Java Thread Class





Transparency:


Do not have to change MC / AC


Activation on demand

10

10

Our Approach



Modification of the java.lang.Thread class


Bytecode injection using the ASM tool


Any thread includes these modifications and can be controlled by areas




Area Management Framework


Each thread is assigned to an area when it starts, according to a criterion


e.g.
, the package of the instance that create the thread


Each area defines a manageable limit, and can trigger an alarm when the limit
is reached

11

11

Area & Alarm Concepts



An area


is an entity for monitoring a pool of resources (
eg.

Threads)


can support children areas


counts the number of Threads for itself and each child recursively


can block the execution of the thread


can trigger alarms



An alarm can have several behaviours:


save alarm messages in a log file


throw exceptions


send a mail to an administrator


composition of different features


12

12

Where to Adapt the Thread class ?


Never more than

X Threads

After thread exits

Before thread starts


Thread activity.


13

13

How to Rewrite the Thread Class ?



Bytecode injection (ASM)


org.objectweb.area.thread.AdaptThreadClass

class
Thread

{



public Area area;



public void
start
();



private void
exit
();

}

class
Thread

{






public void
start
();



private void
exit
();

}

ASM

14

14

Framework Organization



API


AreaProvider : management of the areas


Area : management of the resources


AreaProperties : management of the area features


AreaStatistics : build statistics on the resources


Alarm : send alerts



Current implementation of TMF:


lib


SingletonAreaProvider: JVM bootstrap


DefaultArea, DefaultAlarm, DefaultXXX,… : all interfaces default implementation


SAXHandler: area configuration


NoLimitArea, OutOfMemoryAlarm


thread


AdaptThreadClass: ASM patch


ThreadManager: static class for the delegation of the management to AMF

15

15

TMF Default Implementation



DefaultArea


enter (resource)


parent.enter (resource)


If (counter == 0)


alarm.alert (this, resource)


wait ()


counter = counter
-
1


exit (resource)


counter = counter + 1


notify ()


parent.exit (resource)

16

16

AMF Architecture



Graph of Areas / Alarms


Managed by an AreaProvider


Configurable by users (XML)


Global view from the root Area

<
area

name=
"OTM"

description=
"ObjectWeb Thread Management"

limit=
"500"
>


<
alarm

class=
"org.objectweb.area.lib.DefaultAlarm"
/> <!


Alarm2
--
>


<
area

name=
"java"

description=
"Java packages"

limit=
"100"
>


<
java

package=
"java."
/>


<
java

package=
"javax."
/>


<
java

package=
"sun."
/>


<
alarm

class=
"org.objectweb.area.lib.OutOfMemoryAlarm"
/> <!


Alarm1
--
>


<
/area
>


<
area

name=
"ObjectWeb"

description=
"ObjectWeb packages"

limit=
"100"
>


<
java

package=
"org.objectweb."
/>


<
/area
>


<
area

name=
"local"

description=
"Local packages"

limit=
"100"
>


<
java

package=
""
/>


<
/area
>

<
/area
>

17

17

Fractal Component Based Approach



TMF can be built either in an Object version or in a Component one


Area configuration via Fractal ADL

18

18

Integration into PEtALS



Basic integration for monitoring Middleware Components (MC) activity


Add TMF libraries in the java.endorsed.dirs property




Fine grain integration for monitoring Application Components (AC) activity


Modify the JBI Installer component in order to notify AMF for a reconfiguration of its
Areas


String componentClassName =

componentDescription.getComponentClassName();

int lastSeparator = componentClassName.lastIndexOf('.');

String
packageName

=


componentClassName.substring(0, lastSeparator + 1);

PetalsService.
addPackageInPetalsArea
(
packageName
);

19

19

Conclusion



Overhead < 1 sec



Benchmark :


+ 20% when classical launch



+ 4 % with a SingletonAreaProvider




Tested with RUBiS : non measurable overhead



Threads allocation can be managed


transparently inside the Application Server, for Middleware Components


with minor modifications (of the Application Server source code) for
Application Components

Mean time is 13767 milliseconds.

14373 milliseconds.

16593 milliseconds.

20

20

Perspectives



Other software monitoring


change the AreaProvider



Integration into other middleware:


JORAM


DREAM



Manage other resources, e.g. :


Messages


Sockets


DBConnections




Requires ‘only’ to adapt the resource class, to use the Area Management
Framework


21

21

Thank You




Any questions ?


TMF available at:


http://tmf.gforge.inria.fr

TMF for JOnAS available at:


http://jonas.objectweb.org

TMF for PEtALS (soon) available at:


http://petals.objectweb.org