Web page designs are becoming innovative with rich interface which involve extra code such as java scripts, css, and images etc. Most of the end-user response time tied-up in downloading these components.Optimizations of number of http requests and response size are the key parameters to improve the web application performance. Continue reading “Improve Performance by caching and compression”
Tag: Performance
Oracle Service Registry
Comprehensive UDDI v3 compliance—Provides a standards-based mechanism for dynamic discovery of services and their associated policies during runtime
SOA agility—Keeps SOA infrastructure up-to-date with changes to service end points, ensuring your SOA doesn’t break
End-to-end SOA Lifecycle Management—Serves as the UDDI interface to Oracle Enterprise Repository for support of end-to-end management of the SOA lifecycle
Hot-pluggable—Supports heterogeneous services from any vendor
You can use Oracle SOA Suite with the following versions of OSR:
- OSR 10.3 (with Oracle WebLogic Server 10.3)
- OSR 11g
This section describes how to integrate Oracle Service Registry with Oracle SOA Suite 11g. It contains the following topics:
1. Integrating with Oracle JDeveloper
To create a connection between the Oracle Service Registry and JDeveloper:
- Go to Oracle JDeveloper.
- Select File > New > Connections > UDDI Registry Connection to create a UDDI connection.
- Enter a connection name.
- Enter an inquiry endpoint URL. For example: http://myhost.us.oracle.com:7001/registry/uddi/inquiry
- Ensure that the Business View option is selected.
- Click Next.
- Click Test Connection.
- If successful, click Finish. Otherwise, click the Back button and correct your errors.
2. Configuring Oracle Service Registry at Runtime
Oracle SOA Suite uses the SCA standard as a way to assemble service components into a SOA composite application. SCA provides a programming model for the following:
- Creating service components written with a wide range of technologies, including programming languages such as Java, BPEL, C++, and declarative languages such as XSLT. The use of specific programming languages and technologies (including web services) is not required with SCA.
- Assembling the service components into a SOA composite application. In the SCA environment, service components are the building blocks of applications.
- SCA provides a model for assembling distributed groups of service components into an application, enabling you to describe the details of a service and how services and service components interact. Composites are used to group service components and wires are used to connect service components. SCA helps to remove middleware concerns from the programming code by applying infrastructure declaratively to composites, including security and transactions.
- The key benefits of SCA include the following:
- Loose coupling: Service components integrate with other service components without needing to know how other service components are implemented.
- Flexibility
- Service components can easily be replaced by other service components.
- Services Invocation
- Services can be invoked either synchronously or asynchronously.
- Productivity: Service components are easily integrated to form a SOA composite application.
- Easy Maintenance and Debugging: Service components can be easily maintained and debugged when an issue is encountered.
The Oracle Service Registry (OSR) provides a common standard for publishing and discovering information about web services. This section describes how to configure OSR against a separately installed Oracle SOA Suite environment:
3. Publishing and Browsing the Oracle Service Registry
This section provides an overview of how to publish a business service. For specific instructions, see the documentation at the following URL:
To Manually Publish a Business Service
- Go to the Registry Control: http://hostname:port/registry/uddi/web
- Click Publish > WSDL.
- Log in when prompted.
- Complete the fields on this page to specify the access point URL and publish the WSDL for the business service. The following screen provides details.
- Select one of the following deployment options:
- Dynamically resolve the SOAP endpoint location at runtime.
- Dynamically resolve the concrete WSDL location at runtime.
- The following screen provides details.
- Click OK. You are returned to the Create Web Service dialog.
- See the following section based on your selection in the UDDI Deployment Options dialog.
- Complete the remaining fields in the Create Web Service dialog, and click OK. The Create Web Service dialog looks as shown in the following screen.
- Verify the wiring of the reference with the appropriate service component.
- Complete the remaining fields in the Create Web Service dialog, and click OK. The Create Web Service dialog looks as shown in the following screen.
- Verify the wiring of the reference with the appropriate service component.
- Log in to Oracle Enterprise Manager Fusion Middleware Control Console and navigate to Common Properties, as shown in the following screen.
- Specify values for the following properties:
- In the SOA Infrastructure Common Properties page, specify the same UDDI inquiry URL in the Inquiry URL text box, as shown in the following screen, that you specified in the Create UDDI Registry Connection wizard. For example, http://TST.myhost.com:7101/registry/uddi/inquiry.
- Restart the SOA Infrastructure.
- Exit Oracle Enterprise Manager Fusion Middleware Control Console.
- To see endpoint statistics, return to the Registry Control.
- Go to the Manage page and check statistics to see the increase in the number of invocations when not cached (the first time).
Reference:
Java Barcode API
Class member variable initialization
While declaring the class member variables we have to be very confident about the behavior of the member variables. For example some variable are constant and will be same across the class life cycle and some are instance variables which will be tightly bind with the object (instance) of the class.
When an instance of a class is created using new, initialization of the class’s instance variables create for each unique instance.
Always use the static for the member variable which doesn’t change across the objects of the class.
I would try to check the performance using the below code sample:
public class TestClassVariable {
public TestClassVariable() {
// do nothing
}
public String country[] = { “India”, “USA”, “China”, “UK” };
public static void main(String s[]) {
long start, end;
int[] a = new int[1000000];
start = System.currentTimeMillis();
for (int j = 0; j length; j++) {
TestClassVariable tstClassVar = new TestClassVariable();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” “
+ ” milli seconds execution time”);
}
}
Result: 94 milli seconds execution time
In the above code we used country as class instance variable and it takes 94MS but as we know country could be make as static member variable because it will be not going to change across the instances so the correct way to use as static member variable.
So we can change the program slightly and see the figures again
public class TestClassVariable {
public TestClassVariable() {
// do nothing
}
public static String country[] = { “India”, “USA”, “China”, “UK” };
public static void main(String s[]) {
long start, end;
int[] a = new int[1000000];
start = System.currentTimeMillis();
for (int j = 0; j length; j++) {
TestClassVariable tstClassVar = new TestClassVariable();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” “
+ “milli seconds execution time”);
}
}
Result: 16 milli seconds execution time
We could easily figure it out the performance get enhance 6 times then the original one
Calling object inside the loop
We could use to create the object inside or outside of the loop depends upon the behavior of the class.
If any class having class member variable then class needs to be inside the loop and that will limit their scope which is good to garbage collect but if class used as Utility class and doesn’t have member class variable then we could declare the class out side of the loop and used inside the loop.
Below example shows there are only 32 ms would take to instantiate the object inside the loop but best thing is that it would limit the scope which is good during garbage collection
public class TestLoop {
public static void main(String s[]) {
long start, end;
int[] a = new int[1000000];
start = System.currentTimeMillis();
TestName tname1 = new TestName();
for (int i = 0; i
// tname1=new TestName();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” milli “
+ “seconds for One Time Loop”);
start = System.currentTimeMillis();
for (int j = 0; j
TestName tname = new TestName();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” “
+ “milli seconds loop calling object inside Loop “);
}
}
Result: 0 milli seconds for One Time Loop
32 milli seconds for loop calling object inside Loop
As per above example you could see the declaring the object inside loop doesn’t have much impact on performance.
In below example explain the two ways to declare the object option 1 inside declaration and option 2 out side declaration.
Option 1:
for (int i=0; i
{
Object obj = tempList.get(i);
o. doOperation();
}
Option 2:
Object o;
for (int i=0; i
{
o = tempList.get(i);
o.doOperation();
}
We could say that Option1 better as it restricts scope of ‘obj’ variable to the for block. From a performance perspective, it might not have any effects in Java, but it might have in lower level compilers. They might put the variable in a register if you do the first.
Construction of an object using new is totally different from just declaring it, of course.
I think readability is more important than performance and from a readability standpoint, the first code is definitely better.
But if you have utility class which doesn’t have member variables we could instantiate once and reuse across the code.
In the below example I am trying to explain the utility class which could be instantiate once and use across the application.
import java.util.Calendar;
import java.util.Date;
public class TestLoop {
public static void main(String s[]) {
long start, end;
int[] a = new int[1000000];
Calendar cal = Calendar.getInstance();
start = System.currentTimeMillis();
for (int i = 0; i
Date dt = cal.getTime();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” milli “
+ “seconds for Instantiating object out side Loop”);
start = System.currentTimeMillis();
TestName tname = null;
for (int j = 0; j
Date dt = Calendar.getInstance().getTime();
}
end = System.currentTimeMillis();
System.out.println(end – start + ” “
+ “milli seconds Instantiating object inside Loop “);
}
}
0 milli seconds for Instantiating object out side Loop
797 milli seconds Instantiating object inside Loop
Avoid Nested Loop
Nested loop gives big impact on performance and some time it make worse if not controlled properly. Need to double think before using the nested loop and try to find some alternative way to handle the same. Even if it is used, it should not go to level three in nested loop.
It is explained in the below code.
public class TestLoop {
public static void main(String s[]) {
long start, end;
int[] a = new int[100000];
int[] b = new int[100000];
start = System.currentTimeMillis();
for (int i = 0; i
}
end = System.currentTimeMillis();
System.out.println(end – start + ” ” + “milli seconds for One Time Loop”);
start = System.currentTimeMillis();
for (int j = 0; j
for (int i = 0; i
}
end = System.currentTimeMillis();
System.out.println(end – start + ” ” + “milli seconds for loop B inside Loop A”);
}
}
Result:
0 milli seconds for One Time Loop
44015 milli seconds for loop B inside Loop A
You can see the above result how it becomes 44015 ms for executing the loop inside the loop. These are figure for just an empty loop. For any process getting invoked inside the nested loop, the time will be exorbitantly increase.. I would suggest you to think before using the nesting loop with large data and try to avoid as much as possible. You could try to change/write a code in such a way that it would minimize the nested loop. It is explained using the below code. In the below code I am trying to match the value in a big array and print the ‘Found match’ on the console.
public class TestLoop {
public static void main(String s[]) {
long start, end; String[] arrFirst = new String[1000000];
String[] arrSecond = { “0”, “1” };
for (int i = 0; i length; i++) {
arrFirst[i] = String.valueOf(i);
}
start = System.currentTimeMillis();
for (int i = 0; i length; i++) {
for (int j = 0; j length; j++) {
if (arrFirst[i].equalsIgnoreCase(arrSecond[j])) {
System.out.println(“Found match”);
}
}
}
end = System.currentTimeMillis();
System.out.println(end – start + ” milli “+ “seconds for “);
start = System.currentTimeMillis();
}
}
Result: 30 ms
As you can see that it iterate the 1000000*2 times to complete the process. Since we know arrSecond having only two values 0 and 1 therefore we could easily minimize the code using below way
public class TestLoop1 {
public static void main(String s[]) {
long start, end;
String[] arrFirst = new String[1000000];
String[] arrSecond = { “0”, “1” };
for (int i = 0; i length; i++) {
arrFirst[i] = String.valueOf(i);
}
start = System.currentTimeMillis();
for (int i = 0; i length; i++) {
if ((arrSecond[0].equalsIgnoreCase(arrFirst[i]))|| (arrSecond[1].equalsIgnoreCase(arrFirst[i]))) {
System.out.println(“Found match”);
}
}
end = System.currentTimeMillis();
System.out.println(end – start + ” milli “+ “seconds for loop”);
}
}
Result: 15 ms
You could see it just iterate 1000000 times just half the above code and performance get improved twice.
I agree that this is not the best example but this would definitely provide you the way how to handle the nested loop
Java Loop
Loop
Loops provide efficient way for repeating a piece of code as many times as required. Java has three ways to use the loop control structures and these are:
For Loop: The ‘For-Loop’ is used when we know in advance how many iteration is required
While Loop: The while loop is used when we do not know in advance the number of iterations required so each time before entering the loop the condition is checked and if it is true then the loop get executed
Do-While Loop: The do-while loop is always executed at least once and then the condition is checked at the end of the loop. Developer has to avoid using the do-while loop since it marks major bottleneck in the code.
Since loop repeats the piece of code therefore it gives more cause for performance and need to be very careful during the implementation