|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 5
Offsprings Example
Let's consider simple DelayedClient and DelayedService examples from the package net.sourceforge.offsprings.examples. The DelayedService interface includes several API signatures intended to illustrate some of the basic argument/return type combinations that
the splitter supports:
public List<Document> getDocListFromIdList(List<String> ids); public Map<String,Document> getDocMapFromIdList(List<String> ids); public Document[] getDocArrayFromIdArray(String[] ids); public InputStream getInputStreamFromIdList(List<String> ids); public InputStream getInputStreamFromIdArray(String[] ids); public void processObjectsById(List<String> ids);
The implementation that DelayedServiceImpl provides includes a specific delay of 10 milliseconds per document. The getInputStreamFromId methods return XML that looks like this:
<?xml version='1.0' encoding='UTF-8'?> <delayed_service> <docs>
<doc source="delayedSerive"><id>0</id> <content>This is a content of the document: 0</content> </doc> <doc source="delayedSerive"><id>1</id> <content>This is a content of the document: 1</content> </doc> </docs> <meta_info> <document_count>2</document_count><processing_time>2</processing_time> </meta_info> </delayed_service>
Note that the XML document above has two different content parts: documents content (xpath: delayed_service/docs)and meta info content (xpath: delayed_service/meta_info).
The final documents content is simply the documents content from each of the different batches merged within a single <docs> element. However, the meta content (such as document count) should be merged based on the meaning of the tags (e.g. resulting
count is a sum of count from all batches).
DelayedServiceClient demonstrates usage of the DelayedService API with and without splitter.
The conventional single threaded execution without splitter:
DelayedService service = new DelayedServiceImpl();
client.setService(service);
List docsList = client.processLists();
Map docsMap = client.processMap();
InputStream in = client.processInputStream();
To use splitter, we instead access the DelayedService via the SplitterFactory in the Spring Application Context (configuration within the Application Context is covered below):
String[] contextFiles = {"classpath:exampleContext.xml"};
SplitterFactory factory = SplitterFactory.getInstance(contextFiles, "defaultSplitterFactory");
service = (DelayedService)factory.getBean("delayedService");
client.setService(service);
The output shows the performance boost on the 10 threads splitter and, no wonder, we have almost 10 times better results:
Process List. Time to process 1000 documents: 10015; per document: 10.015 Input Stream. Time to process 1000 documents: 10121; per document: 10.121 Splitter is engaged ... Process List. Time to process 1000 documents: 1039; per document: 1.039 Input Stream. Time to process 1000 documents: 1255; per document: 1.255
DelayedClient example configuration
The example Application Context configuration files is example-context.xml. Configuration is consistent with the usual Spring AOP approach.