Bug 149248 - Minor improvement of ServiceRegistrationImpl
Summary: Minor improvement of ServiceRegistrationImpl
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: 3.3 M1   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2006-06-29 17:26 EDT by Ikuo Yamasaki CLA
Modified: 2006-08-23 15:20 EDT (History)
3 users (show)

See Also:


Attachments
Patch of ServiceRegistrationImpl (1.29 KB, patch)
2006-06-29 17:27 EDT, Ikuo Yamasaki CLA
no flags Details | Diff
Patch of ServiceRegistrationImpl(revised) (1.31 KB, patch)
2006-06-30 08:57 EDT, Ikuo Yamasaki CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ikuo Yamasaki CLA 2006-06-29 17:26:12 EDT
The following patch will improve performance of registering service and changing properties of registered services ( more precisely speaking, create properties). ( I don't think it improves so much but surely.)
Comment 1 Ikuo Yamasaki CLA 2006-06-29 17:27:36 EDT
Created attachment 45559 [details]
Patch of ServiceRegistrationImpl
Comment 2 BJ Hargrave CLA 2006-06-29 19:16:28 EDT
Seems we are really doing very minor enhancements now... :-)

Anyway, there is a problem in the patch.

+		properties.set(Constants.OBJECTCLASS, clazzes,true);


must be changed to 

+		properties.set(Constants.OBJECTCLASS, cloneValue(clazzes), true);

You must not expose the internal clazzes array to the bundles since arrays are mutable and a bundle can alter the elements of the internal array. You must clone the array and then present the cloned array to the bundles. 

This problem does not exist for service.id since Long is immutable.
Comment 3 Ikuo Yamasaki CLA 2006-06-30 08:57:48 EDT
Created attachment 45575 [details]
Patch of ServiceRegistrationImpl(revised)

Thanks BJ.
What you said is right. The attached one is revised.
I'll do performance tests against codes with this patch for confirmation ( although I guess the contribution in terms of performance will be a little.)
Comment 4 Ikuo Yamasaki CLA 2006-06-30 16:29:05 EDT
I did my performance tests which both the first patch and the second of Bug#149030 and the latest patch of Bug#149248(This bug) are applied.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=149030
https://bugs.eclipse.org/bugs/show_bug.cgi?id=149248

First of all, I currently have a problem in my performance tests that results vary.
---------------------------------------------------------------
Registering 10,000 services takes totally
		(a)		(b)		(c)
With 3 props:	6.617	->	6.494	->	6.299[sec]
With no props:	5.051	->	4.895	->	4.917[sec]

(a) before fix of Bug#149030
(b) after fix of Bug#149030
(c) after fix of Bug#149030 and  Bug#149248
---------------------------------------------------------------
Although there are inversion between (b) and (c) unfortunately, it seems within the margin of error.

I believe these patches improve performance of not getServiceReference()/getService(reference) but registerService().

P.S. I cannot see difference for getService(ref)/getServiceReference().
Comment 5 Chris Aniszczyk CLA 2006-06-30 16:32:16 EDT
Excuse me if I'm a dolt for asking this question Ikuo, but would it be possible fo r you to share (possibly on the Equinox Wiki) on how you perform these tests? I love the work and it would be great if it could be repeated by others :)
Comment 6 Ikuo Yamasaki CLA 2006-06-30 17:18:07 EDT
Hi Chris, thank you for your comment.

Hmm, it's possible I think. But it takes time.
Currently, I run my test code extending PerformanteTestRunner.
In order to run each test independently, I can submit my test codes to share among others (it is possible actually). However, Since I would like to run multiple tests continuously (and effectively) and save each results into csv format under my own specific name, I took some tricky but not sophisticated ways;

# I usually run tests during day and night; It takes so much time....
# I need to be patient sometimes :-)

1. I modified "org.eclipse.test.internal.performance.InternalPerformanceMeter" in "org.eclipse.test.performance" PI by myself to produce a result file under static file name (e.g. "results.csv") at meter.commit().

2. After PerformanceTestRunner.run(), my code renames the file produced "result.csv" into specific name, e.g. "result_NoSt_DMa_5000_5_i8_100.csv", which represents "No use of ServifceTracker, type = DMa, number of types of classes = 5,000, number of registration duplication =5, inner = 8, outer =100". (I don't use Derby DB now)

3. The last test(method) in my test class calculate average values from these files under specified directory and produce "summary.csv". 

Anyway, Jeff, Oleg and I had talked that some of my tests should be included in AutomatedTest before (We didn't start to merge them yet). We'll discuss this topic.

# Posting my codes on wiki might not be permanent solution
# but it is fine for instant one.
Comment 7 Thomas Watson CLA 2006-07-06 10:36:58 EDT
(In reply to comment #2)

BJ your statement about the need for cloneValue(clazzes) is incorrect.  Using the internal classes[] as a value in the internal properties object will not expose the array to other bundles.  The only way bundles may access the properties values is by calling ServiceReference.getProperty method.  This method perperly calls cloneValue on any values returned.
Comment 8 Thomas Watson CLA 2006-07-06 10:37:59 EDT
Comment on attachment 45559 [details]
Patch of ServiceRegistrationImpl

Making patch valid per last comment.
Comment 9 Thomas Watson CLA 2006-07-06 10:38:59 EDT
Comment on attachment 45575 [details]
Patch of ServiceRegistrationImpl(revised)

making patch obsolete per comment 7.
Comment 10 BJ Hargrave CLA 2006-07-06 14:39:33 EDT
(In reply to comment #7)
> (In reply to comment #2)
> 
> BJ your statement about the need for cloneValue(clazzes) is incorrect.  Using
> the internal classes[] as a value in the internal properties object will not
> expose the array to other bundles.  The only way bundles may access the
> properties values is by calling ServiceReference.getProperty method.  This
> method perperly calls cloneValue on any values returned.
> 

Yes. Normally properties are cloned on the way "in" to avoid side effects from the "setter" and cloned on the way "out" to avoid side effects from the "getter". But since the framework is the setter of the clazzes array, we can assume that there will be no side effects from the setter. If the framework gets the array directly from the field, then we must also trust the framework to not cause side effects as the getter.
Comment 11 Ikuo Yamasaki CLA 2006-07-17 17:05:58 EDT
(In reply to comment #6)
> Anyway, Jeff, Oleg and I had talked that some of my tests should be included in
> AutomatedTest before (We didn't start to merge them yet). We'll discuss this
> topic.

I opened a new report and posted my test codes to it. Please check it if you are interested in it.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=150872
Comment 12 Thomas Watson CLA 2006-07-26 14:27:42 EDT
[contributed patch applied]

The fix is safe.  I went ahead and released it into the 3.3 stream.
Comment 13 Thomas Watson CLA 2006-08-23 15:20:39 EDT
adding "contributed" keyword to patches contributed by the community.