27.03.2014 Views

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SEKE 2012 Proceedings - Knowledge Systems Institute

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

A thread is the basic unit to which the operating system<br />

allocates processor time. Thus the CPU utilization of a bundle<br />

is the sum of the CPU time consumed by different threads,<br />

which execute within the bundle. We have two monitoring<br />

perspectives that are bundle and thread. From the bundle<br />

perspective, threads are grouped into different bundles, and<br />

each thread belongs to a specific bundle. Thus we add the CPU<br />

time of every thread in the bundle. From the thread perspective,<br />

a thread execution is divided into some stages, each of which<br />

belongs to a specific bundle. Thus we add the CPU time of<br />

every stage in the bundle. Because of the frequent interactions<br />

between bundles by service invocation, the relations between<br />

bundles and threads vary dynamically. If we follow the first<br />

perspective, the thread schedule model should be modified, and<br />

significant overhead will be introduced as presented in [8].<br />

Therefore, we adopt the second choice through tracing thread<br />

transfer between bundles.<br />

It is easy to calculate CPU time utilized by a thread during<br />

a period using the JVMTI [22] provided by the JVM (Java<br />

Virtual Machine). Thus, how to divide the CPU time of a<br />

thread into different bundles becomes an essential question.<br />

A. Monitoring Dynamic Service Invocation<br />

Algorithm 1 describes the method of monitoring bundle<br />

CPU utilization. Every thread is tagged with a bundle ID, when<br />

a thread is created. OSGi invokes start () method in the<br />

Activator class to start the bundle, when a bundle is initialized.<br />

We set the bundle ID of the thread as the started bundle<br />

through labeling the thread before and after the start method in<br />

the OSGi platform (line 1-3). When a new thread is created, we<br />

set the bundle ID of the thread as that of its parent thread (line<br />

4-8). A thread in bundles is traced to decide whether the thread<br />

transfer happens. When a service is invoked, if the service<br />

provider and the service consumer are in different bundles,<br />

thread transfer happens (line 9-12).<br />

Service proxy is generated and used to provide services.<br />

We use an event-driven mechanism to trace service invocation<br />

through listening to the events in the service registry. To avoid<br />

affecting the execution code in t he original bundle and deal<br />

with the arriving services during execution, we create a proxy<br />

object for every required service (line 13-16). Figure 4<br />

describes the event-driven monitoring method. A proxy class is<br />

generated when a service is registered. The proxy class is<br />

instantiated when the service is invoked. We also modify the<br />

service registry to redirect service requests to the service proxy.<br />

Thus the proxy object instead of the original service provides<br />

Figure 1 Proxy Generation<br />

service for a service consumer transparently. In every proxy<br />

class, the monitoring point is ins erted before and after the<br />

service invocation to label the changed bundle ID of a thread.<br />

The CPU time of every bundle is calculated. If the bundle<br />

ID of a thread varies after entering the invoked service, the<br />

CPU time is calculated and added to the original bundle, and<br />

the time stamp is updated (line 17-21). After exiting from the<br />

service, the CPU time is calculated and added to the invoked<br />

bundle (line 22-28). Finally, the monitor calculates the CPU<br />

utilization for every bundle in period (line 29-31).<br />

Algorithm 1Bundle CPU monitoring<br />

Input: OSGi-based software<br />

Output: u 1 ,u 2 ,…,u n , where n is the number of bundles<br />

1. LISTEN (bundle b is initialized)<br />

2. SET the bundle ID of thread t as b ;<br />

3. SET time stamp for t ;<br />

4. LISTEN (thread ts is initialized)<br />

5. GET current thread tp; //tp is the parent of ts<br />

6. GET bundle ID of tp as bp;<br />

7. CREATE new thread ts;<br />

8. SET bundleID of ts as bp;<br />

9. LISTEN (service s i invoke service s j )<br />

10. GET the bundle ID of s i as b i ;<br />

11. GET the bundle ID of s j as b j ;<br />

12. IF (b i != b j )<br />

13. GET proxy of s j as p j ;<br />

14. IF (p j = NULL)<br />

15. CREATE p j for s j ;<br />

16. ENDIF<br />

17. GET bundle_info i of b i ;<br />

18. GET current thread t;<br />

19. bundle_info i .CPUTime += t.Calculate_CPU();<br />

20. SET time stamp for t ;<br />

21. SET bundle ID of thread t as b j ;<br />

22. EXECUTE p ;<br />

23. GET bundle_info j of b j ;<br />

24. bundle_Info j .CPUTime += t.Calculate_CPU() ;<br />

25. SET time stamp for t ;<br />

26. SET bundle ID of t as b i ;<br />

27. EXIT p ;<br />

28. ENDIF<br />

29. FOR (i=1;i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!