Saturday, August 20, 2011

Liferay >>> open Liferay popup in web content

This post is about the solution to the problem i faced in liferay where i need to open one or more Liferay styled modal popups from web content portlet or similarly from any other portlet. In my case the popup i need to open is that of feedback from user. The steps i took to get it working are:

  1. To start with add an anchor tag in the web content portlet on which you want to open up a feedback popup
    <a id="" class="feedback_popup"> Submit Feedback</a>

  2. Now you need to go to the theme/javascript folder and edit javascript.js file. Add to it the code

    jQuery(document).ready(
    function() {
    th_FeedbackPopup()
    }
    );

    function th_FeedbackPopup() {
    jQuery(document).find("a.feedback_popup").click(function() {
    var url = new Liferay.PortletURL.createRenderURL();
    url.setPortletId("FEEDBACK_1");
    url.setWindowState("exclusive");
    url.setPortletMode("view");
    url.setParameter("struts_action", "/ext/feedvack/view");
    var popup = Liferay.Popup({
    draggable:false,
    width:500,
    height:'auto',
    url:url.toString(),
    resizable:false,
    modal:true,
    title:'Submit Feedback',
    position:[250,20]
    });
    });
    }
    The idea behing javascript is to bind the click event of all anchor elements on page having class "feedback_popup" to open a modal popup. Make sure that you should bind the event based on class name and not on element id as a page can have multiple such elements.

Better Faster Lighter Java

The section is designed to help you make the most effective use of the Java™ programming language and its fundamental libraries, java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io. It discusses other libraries from time to time, but it does not cover graphical user interface programming, enterprise APIs, or mobile devices. Section consists of 9 items, each of which conveys one rule. The rules capture practices generally held to be beneficial by the best and most experienced programmers. Many new features were added to the platform in Java 5. Most of the items here try to cover these features in some way.
  1. Minimize the scope of local variablesBy minimizing the scope of local variables, you increase the readability and maintainability of your code and reduce the likelihood of error. The most powerful technique for minimizing the scope of a local variable is to declare it where it is first used. Declaring a local variable prematurely can cause its scope not only to extend too early, but also to end too late. The scope of a local variable extends from the point where it is declared to the end of the enclosing block. If a variable is declared outside of the block in which it is used, it remains visible after the program exits that block. If a variable is used accidentally before or after its region of intended use, the consequences can be disastrous. Nearly every local variable declaration should contain an initializer. If you don’t yet have enough information to initialize a variable sensibly, you should postpone the declaration until you do.
    // Preferred idiom for iterating over a collection
    for (Element e : c) {
    doSomething(e);
    }
    Here is another loop idiom that minimizes the scope of local variables:
    for (int i = 0, n = expensiveComputation(); i < n; i++)
    {
    doSomething(i);
    }
    A final technique to minimize the scope of local variables is to keep methods small and focused. If you combine two activities in the same method, local variables relevant to one activity may be in the scope of the code performing the other activity. To prevent this from happening, simply separate the method into two: one for each activity.
  2. Know and use the librariesDon’t reinvent the wheel. If you need to do something that seems like it should be reasonably common, there may already be a class in the libraries that does what you want. If there is, use it; if you don’t know, check. Generally speaking, library code is likely to be better than code that you’d write and is likely to improve over time. Advantages of using library are:- Firstly by using a standard library, you take advantage of the knowledge of the experts who wrote it and the experience of those who used it before you. A second advantage of using the libraries is that you don’t have to waste your time writing ad hoc solutions to problems that are only marginally related to your work. Third advantage of using standard libraries is that their performance tends to improve over time, with no effort on your part. Because many people use them and because they’re used in industry-standard benchmarks also. Many of the Java platform libraries have been rewritten over the years, sometimes repeatedly, resulting in dramatic performance improvements. A final advantage of using the standard libraries is that you place your code in the mainstream. Such code is more easily readable, maintainable, and reusable by the multitude of developers.

  3. Prefer primitive types to boxed primitivesJava has a two-part type system, consisting of primitives, such as int, double, and boolean, and reference types, such as String and List. Every primitive type has a boxed primitives corresponding to it, like int, double, and boolean are Integer, Double, and Boolean. To summarize, use primitives in preference to boxed primitives whenever you have the choice. Primitive types are simpler and faster. If you must use boxed primitives, be careful! Autoboxing reduces the verbosity, but not the danger, of using boxed primitives. When your program compares two boxed primitives with the == operator, it does an identity comparison, which is almost certainly not what you want. When your program does mixed-type computations involving boxed and unboxed primitives, it does unboxing, and when your program does unboxing, it can throw a NullPointerException. Finally, when your program boxes primitive values, it can result in costly and unnecessary object creations.
  4. Avoid strings where other types are more appropriateStrings are designed to represent text, and they do a fine job of it. Because strings are so common and so well supported by the language, there is a natural tendency to use strings for purposes other than those for which they were designed. This item discusses a few things that you shouldn’t do with strings.
    • Strings are poor substitutes for other value types.
    • Strings are poor substitutes for enum types.
    • Strings are poor substitutes for aggregate types.
    • Strings are poor substitutes for capabilities.
    To summarize, avoid the natural tendency to represent objects as strings when better data types exist or can be written. Used inappropriately, strings are more cumbersome, less flexible, slower, and more error-prone than other types. Types for which strings are commonly misused include primitive types, enums, and aggregate types.
  5. Beware the performance of string concatenationThe string concatenation operator (+) is a convenient way to combine a few strings into one. It is fine for generating a single line of output or for constructing the string representation of a small, fixed-size object, but it does not scale. Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic in n. It is an unfortunate consequence of the fact that strings are immutable. When two strings are concatenated, the contents of both are copied.
    // Inappropriate use of string concatenation - Performs horribly!
    public String statement() {
    String result = "";
    for (int i = 0; i < numItems(); i++)
    result += lineForItem(i);
    // String concatenation return result;
    }
    This method performs abysmally if the number of items is large. To achieve acceptable performance, use a StringBuilder in place of a String to store the statement under construction. The StringBuilder class, added in release 1.5, is an unsynchronized replacement for StringBuffer, which is now obsolete. The difference in performance is dramatic.
  6. Use loggingWhile building an application or doing debugging to trace out the control flow to rectify a bug always use standard logging libraries. Below are wrong and right way do keep control over logging.
    WRONG
    public void bar() {
    try {
    //doSomething()
    }
    catch (JMSException e) {
    System.out.println("exception occurred"); e.printStackTrace();
    }
    finally {
    System.out.println("cleaning up");
    }
    }
    RIGHT
    public void bar() {
    try {
    // ...
    }
    catch (JMSException e) {
    logger.log(Level.WARNING, "JMS Problem", e);
    } finally {
    logger.info("cleaning-up");
    }
    }

    Wrap complex logging expressions into conditions
    if (logger.isDebugEnabled()) {
    logger.debug("Message: " + object.calculateSomething() + ", count=" + cnt);
    }
  7. Code Formatting and stylingThere are 2 standard plugins available for Eclipse PMD and CheckStyle which comes to rescue
    • CheckStyle
      • http://checkstyle.sourceforge.net/index.html
      • Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.
      • Checkstyle will help you during your programming by checking your coding style i.e braces, naming etc. Simple things but very numerous!
      • Checkstyle is highly configurable and can be made to support almost any coding standard.
      • Historically it's main functionality has been to check code layout issues
      • Checkstyle is most useful if you integrate it in your build process or your development environment.
    • PMD
      • http://pmd.sourceforge.net/
      • PMD scans Java source code and looks for potential problems like:
        • Possible bugs - empty try/catch/finally/switch statements
        • Dead code - unused local variables, parameters and private methods
        • Suboptimal code - wasteful String/StringBuffer usage
        • Overcomplicated expressions - unnecessary if statements, for loops that could be while loops Duplicate code - copied/pasted code means copied/pasted bugs
      • PMD is also able to point out questionable coding practices and its output is generally more relevant and useful.
      • PMD will help you by checking more complicate rules like during the design of your classes, or for more special problems like implementing correctly the clone function. Simply, PMD will check your programming style
      • PMD to find problematic code areas and next refactoring targets
    Checkstyle and PMD both are good at checking coding standards and are easy to extend. But PMD has additional rules to check for cyclomatic complexity,Npath complexity,etc which allows you write healthy code.
  8. Adhere to generally accepted naming conventions
    The Java platform has a well-established set of naming conventions, many of which are contained in The Java Language Specification. Loosely speaking, naming conventions fall into two categories: typographical and grammatical. There are only a handful of typographical naming conventions, covering packages, classes, interfaces, methods, fields, and type variables. You should rarely violate them and never without a very good reason. If an API violates these conventions, it may be difficult to use. If an implementation violates them, it may be difficult to maintain. In both cases, violations have the potential to confuse and irritate other programmers who work with the code and can cause faulty assumptions that lead to errors.

Sunday, August 14, 2011

HTTPComponents client 4.1.2 >>> Invalid use of SingleClientConnManager: connection still allocated

In most of the ideal case scenarios single inialization of DefaultHttpClient will serve the purpose. However this singleton implementaion approach can lead to some problems. Since the resource designed as Singleton pattern becomes effectively global, doing things like modifying the time out value, or forcibly closing the connection manager (as one commenter pointed out), could lead to the HttpClient to be in an invalid or undesired state when reused at a different time or in a differentscenario in the same application.

Luckily, after much surfing I stumbled upon Jason Hudgin’s site where he created a convenience method that avoids this problem.
To overcome this the modified basic implemntaion will lead to something written below:

public static DefaultHttpClient getThreadSafeClient() {

DefaultHttpClient httpClient = new DefaultHttpClient();
ClientConnectionManager mgr = httpClient.getConnectionManager();
HttpParams params = httpClient .getParams();

httpClient = new DefaultHttpClient(
new ThreadSafeClientConnManager(params,
mgr.getSchemeRegistry()), params);

return httpClient ;
}

The right place to use something like this is when you want to download multiple items from a single remote machine, for example, if you need to make concurrent requests to any service on server to download image or do any CRUD operation and all requests sharing one HttpClient instance, reusing HTTP connections as they became available.

Monday, June 13, 2011

Better Faster Lighter Java

The section is designed to help you make the most effective use of the Java™ programming language and its fundamental libraries, java.lang, java.util, and, to a lesser extent, java.util.concurrent and java.io. It discusses other libraries from time to time, but it does not cover graphical user interface programming, enterprise APIs, or mobile devices. Section consists of 9 items, each of which conveys one rule. The rules capture practices generally held to be beneficial by the best and most experienced programmers. Many new features were added to the platform in Java 5. Most of the items here try to cover these features in some way.
  1. Minimize the scope of local variablesBy minimizing the scope of local variables, you increase the readability and maintainability of your code and reduce the likelihood of error. The most powerful technique for minimizing the scope of a local variable is to declare it where it is first used. Declaring a local variable prematurely can cause its scope not only to extend too early, but also to end too late. The scope of a local variable extends from the point where it is declared to the end of the enclosing block. If a variable is declared outside of the block in which it is used, it remains visible after the program exits that block. If a variable is used accidentally before or after its region of intended use, the consequences can be disastrous. Nearly every local variable declaration should contain an initializer. If you don’t yet have enough information to initialize a variable sensibly, you should postpone the declaration until you do.
    // Preferred idiom for iterating over a collection
    for (Element e : c) {
    doSomething(e);
    }
    Here is another loop idiom that minimizes the scope of local variables:
    for (int i = 0, n = expensiveComputation(); i < n; i++)
    {
    doSomething(i);
    }
    A final technique to minimize the scope of local variables is to keep methods small and focused. If you combine two activities in the same method, local variables relevant to one activity may be in the scope of the code performing the other activity. To prevent this from happening, simply separate the method into two: one for each activity.
  2. Know and use the librariesDon’t reinvent the wheel. If you need to do something that seems like it should be reasonably common, there may already be a class in the libraries that does what you want. If there is, use it; if you don’t know, check. Generally speaking, library code is likely to be better than code that you’d write and is likely to improve over time. Advantages of using library are:- Firstly by using a standard library, you take advantage of the knowledge of the experts who wrote it and the experience of those who used it before you. A second advantage of using the libraries is that you don’t have to waste your time writing ad hoc solutions to problems that are only marginally related to your work. Third advantage of using standard libraries is that their performance tends to improve over time, with no effort on your part. Because many people use them and because they’re used in industry-standard benchmarks also. Many of the Java platform libraries have been rewritten over the years, sometimes repeatedly, resulting in dramatic performance improvements. A final advantage of using the standard libraries is that you place your code in the mainstream. Such code is more easily readable, maintainable, and reusable by the multitude of developers.

  3. Prefer primitive types to boxed primitivesJava has a two-part type system, consisting of primitives, such as int, double, and boolean, and reference types, such as String and List. Every primitive type has a boxed primitives corresponding to it, like int, double, and boolean are Integer, Double, and Boolean. To summarize, use primitives in preference to boxed primitives whenever you have the choice. Primitive types are simpler and faster. If you must use boxed primitives, be careful! Autoboxing reduces the verbosity, but not the danger, of using boxed primitives. When your program compares two boxed primitives with the == operator, it does an identity comparison, which is almost certainly not what you want. When your program does mixed-type computations involving boxed and unboxed primitives, it does unboxing, and when your program does unboxing, it can throw a NullPointerException. Finally, when your program boxes primitive values, it can result in costly and unnecessary object creations.
  4. Avoid strings where other types are more appropriateStrings are designed to represent text, and they do a fine job of it. Because strings are so common and so well supported by the language, there is a natural tendency to use strings for purposes other than those for which they were designed. This item discusses a few things that you shouldn’t do with strings.
    • Strings are poor substitutes for other value types.
    • Strings are poor substitutes for enum types.
    • Strings are poor substitutes for aggregate types.
    • Strings are poor substitutes for capabilities.
    To summarize, avoid the natural tendency to represent objects as strings when better data types exist or can be written. Used inappropriately, strings are more cumbersome, less flexible, slower, and more error-prone than other types. Types for which strings are commonly misused include primitive types, enums, and aggregate types.
  5. Beware the performance of string concatenationThe string concatenation operator (+) is a convenient way to combine a few strings into one. It is fine for generating a single line of output or for constructing the string representation of a small, fixed-size object, but it does not scale. Using the string concatenation operator repeatedly to concatenate n strings requires time quadratic in n. It is an unfortunate consequence of the fact that strings are immutable. When two strings are concatenated, the contents of both are copied.
    // Inappropriate use of string concatenation - Performs horribly!
    public String statement() {
    String result = "";
    for (int i = 0; i < numItems(); i++)
    result += lineForItem(i);
    // String concatenation return result;
    }
    This method performs abysmally if the number of items is large. To achieve acceptable performance, use a StringBuilder in place of a String to store the statement under construction. The StringBuilder class, added in release 1.5, is an unsynchronized replacement for StringBuffer, which is now obsolete. The difference in performance is dramatic.
  6. Use loggingWhile building an application or doing debugging to trace out the control flow to rectify a bug always use standard logging libraries. Below are wrong and right way do keep control over logging.
    WRONG
    public void bar() {
    try {
    //doSomething()
    }
    catch (JMSException e) {
    System.out.println("exception occurred"); e.printStackTrace();
    }
    finally {
    System.out.println("cleaning up");
    }
    }
    RIGHT
    public void bar() {
    try {
    // ...
    }
    catch (JMSException e) {
    logger.log(Level.WARNING, "JMS Problem", e);
    } finally {
    logger.info("cleaning-up");
    }
    }

    Wrap complex logging expressions into conditions
    if (logger.isDebugEnabled()) {
    logger.debug("Message: " + object.calculateSomething() + ", count=" + cnt);
    }
  7. Code Formatting and stylingThere are 2 standard plugins available for Eclipse PMD and CheckStyle which comes to rescue
    • CheckStyle
      • http://checkstyle.sourceforge.net/index.html
      • Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard.
      • Checkstyle will help you during your programming by checking your coding style i.e braces, naming etc. Simple things but very numerous!
      • Checkstyle is highly configurable and can be made to support almost any coding standard.
      • Historically it's main functionality has been to check code layout issues
      • Checkstyle is most useful if you integrate it in your build process or your development environment.
    • PMD
      • http://pmd.sourceforge.net/
      • PMD scans Java source code and looks for potential problems like:
        • Possible bugs - empty try/catch/finally/switch statements
        • Dead code - unused local variables, parameters and private methods
        • Suboptimal code - wasteful String/StringBuffer usage
        • Overcomplicated expressions - unnecessary if statements, for loops that could be while loops Duplicate code - copied/pasted code means copied/pasted bugs
      • PMD is also able to point out questionable coding practices and its output is generally more relevant and useful.
      • PMD will help you by checking more complicate rules like during the design of your classes, or for more special problems like implementing correctly the clone function. Simply, PMD will check your programming style
      • PMD to find problematic code areas and next refactoring targets
    Checkstyle and PMD both are good at checking coding standards and are easy to extend. But PMD has additional rules to check for cyclomatic complexity,Npath complexity,etc which allows you write healthy code.
  8. Adhere to generally accepted naming conventions
    The Java platform has a well-established set of naming conventions, many of which are contained in The Java Language Specification. Loosely speaking, naming conventions fall into two categories: typographical and grammatical. There are only a handful of typographical naming conventions, covering packages, classes, interfaces, methods, fields, and type variables. You should rarely violate them and never without a very good reason. If an API violates these conventions, it may be difficult to use. If an implementation violates them, it may be difficult to maintain. In both cases, violations have the potential to confuse and irritate other programmers who work with the code and can cause faulty assumptions that lead to errors.

Agile Software/Web Development

Agile software development is a group of software development methodologies based on iterative and incremental development, where requirements and solutions evolve through collaboration between self-organizing, cross-functional teams. In fact it is a framework that promotes development iterations throughout the life-cycle of a project. It minimizes risk by developing software in short amounts of time. Developments accomplished in one unit of time (generally up to four weeks) is called an iteration. Each iteration is a project with analysis, design, coding, testing and also documentation All the required functionality may not be covered in one iteration for releasing the project. But it will be covered in multiple iterations. The idea is to have a defect free release available at the end of each iteration.
Being agile is critical if you are to succeed in today‟s competitive world. More and more people are achieving greater productivity and success by applying agile methodology to their work. Organizations of all sizes are achieving greater success by adopting the Agile Method, replacing rigid and inflexible processes with our dynamic and iterative approach.
The Agile Manifesto introduced the term in 2001. Agile Manifesto reads, in its entirety, as follows:
We are uncovering better ways of developing software by doing it and helping others do it. Through this work we have come to value:
  • Individuals and interactions over processes and tools
  • Working software over comprehensive documentation
  • Customer collaboration over contract negotiation
  • Responding to change over following a plan
That is, while there is value in the items on the right, we value the items on the left more.

Twelve principles underlie the Agile Manifesto, including:
  • Customer satisfaction by rapid delivery of useful software
  • Welcome changing requirements, even late in development
  • Working software is delivered frequently (weeks rather than months)
  • Working software is the principal measure of progress
  • Sustainable development, able to maintain a constant pace
  • Close, daily co-operation between business people and developers
  • Face-to-face conversation is the best form of communication (co-location)
  • Projects are built around motivated individuals, who should be trusted
  • Continuous attention to technical excellence and good design
  • Simplicity
  • Self-organizing teams
  • Regular adaptation to changing circumstances
Characteristics
There are many specific agile development methods. Most promote development, teamwork, collaboration, and process adaptability throughout the life-cycle of the project.
Agile methods break tasks into small increments with minimal planning, and do not directly involve long-term planning. Iterations are short time frames that typically last from one to four weeks. Each iteration involves a team working through a full software development cycle including planning, requirements analysis, design, coding, unit testing, and acceptance testing when a working product is demonstrated to stakeholders.
Team composition in an agile project is usually cross-functional and self-organizing without consideration for any existing corporate hierarchy or the corporate roles of team members. Team members normally take responsibility for tasks that deliver the functionality iteration requires.
Agile methods emphasize face-to-face communication over written documents when the team is all in the same location. Most agile teams work in a single open office, which facilitates such communication
No matter what development disciplines are required, each agile team will contain a customer representative. This person is appointed by stakeholders to act on their behalf and makes a personal commitment to being available for developers to answer mid-iteration problem-domain questions.
Most agile implementations use a routine and formal daily face-to-face communication among team members.
Agile development emphasizes working software as the primary measure of progress.

Industry Analysis – Software Developments of 2010

With the end of 2010, it is time to summarize the most significant developments in 2010 in the software development community. It is difficult to judge the importance of events in spaces one is not familiar with, so I tend to favor areas that I do know and am able to make some educated conclusions about their significance.
Thus below are the top major events occurred in the industry.

Java EE 6
Java EE 6 was technically finalized in late 2009, but 2010 has been its year of implementation and adoption. There has been significant enthusiasm for Java EE 6. The question is whether Java EE 6 can lure even more developers away from the Spring Framework and other common alternatives.

.NET Framework 4 and Visual Studio 2010
Roughly 2 1/2 years after the release of .NET 3.5 and Visual Studio 2008, .NET 4 and Visual Studio 2010 were released in April of 2010. .NET Framework 4 offers numerous new features including support for covariance and contra variance for generics, simpler property syntax in VB.NET, optional method parameters in C#, late/dynamic binding in C#, security improvements, improved ability to measure performance diagnostics, background garbage collection as a replacement for concurrent garbage collection, code contracts, and built-in Tuple support.

Oracle/Google Dispute over Android
For those of us who identify ourselves as members of the Java community, this Oracle lawsuit over Android and Java is a big deal because one of the attractive aspects of Android development is the ability to use language syntax we are familiar with to develop applications for mobile devices that run on the Android platform.

The Rise of HTML5
Web developers have been frustrated with HTML/CSS/DOM/JavaScript behavior across major web browsers (particularly the most popular web browser) for years. Developers doubt to some extent regarding adoption of HTML5 at a level that would make it truly viable. Although it's certainly "not there yet," HTML5 finally seems to be gaining the traction it needs among the major browsers and among web developers and authors to be worth paying attention to. In particular, market-leading browsers Google Chrome, Firefox 4 (beta), and Microsoft Internet Explorer 9 (beta) have or are advertised to have significant greater HTML5 support. As important as it is that the desktop web browsers provide consistent HTML5 support to make it more attractive to use, it seems that the mobile device arena is already pushing HTML5 features heavily. Many of the HTML5 features, such as the web forms features, are more useful and more interesting on mobile device browsers, more granular HTML forms controls are truly appreciable.

Cloud Computing
Some developers still have some lingering doubts about cloud computing as a long-term widely applicable concept. Others still question whether it's something a majority of developers will ever really need to deal with as-is, but at this point it's obvious that at least some significant portion of developers will and already are dealing with development for the cloud. With all the major vendors want a piece of the action, there are at least short-term gains associated with that action. IBM, Oracle, and Microsoft have all expressed commitment to cloud computing. Although it's normal for vendors to chase anything new because it's easier to sell products and services for new rather than for familiar. That type of sales pressure often leads to acceptance.

Thursday, April 14, 2011

Optimize: Liferay Performance


Goal: Once you have your portal up and running, you may find a need to tune it for performance, especially if your site winds up generating more traffic than you'd anticipated. There are some definite steps you can take with regard to improving Liferay's performance. The aim is to bring together all the tuning tips and configuration at a single location for reference.
  1. Liferay Configuration
    1. ##Lucene Search
      #Set the following to true if you want to index your entire library 
      of files on startup.
       
      index.on.startup=false
    2. system.properties
       # The layout cache filter will cache pages to speed up page rendering for# guest users. See  ehcache.xml to modify the cache expiration time to live.
      com.liferay.portal.servlet.filters.layoutcache.LayoutCacheFilter=true
    3. Disable unneeded filters
      Liferay comes by default with 15 servlet filters enabled and running. It is likely that for your installation, you don't need them all. Two filters that you can disable without any impact are the Compression Filter and the Strip Filter. These filters are responsible for shrinking the size of the response (to save bandwidth). The Strip Filter removes whitespace from the response object, and the Compression Filter compresses it. This obviously requires some processing, and so disabling these two filters can enhance performance.
      To disable a servlet filter, simply comment it out of your web.xml file.
      If there is a feature supported by a servlet filter that you know you are not using, you can comment it out as well to achieve some performance gains. For example, if you are not using CAS for single sign-on, comment out the CAS Filter. If you are not using NTLM for single sign-ons, comment out the Ntlm Filter. If you are not using the Virtual Hosting for Communities feature, comment out the Virtual Host Filter. The fewer servlet filters you are running, the less processing power is needed for each request.

      There is a known optimilisation for LR 5.0+ Compression Filter
      <filter>
              <filter-name>Cache Filter - Resource CSS JSP</filter-name>
              <filter-class>com.liferay.portal.servlet.filters.cache.CacheFilter</filter-class>
              <init-param>
                  <param-name>url-regex-pattern</param-name>
                  <param-value>.+/(barebone|css|everything)\.jsp</param-value>
              </init-param>
              <init-param>
                  <param-name>pattern</param-name>
                  <param-value>2</param-value>
              </init-param>
          </filter>   
    4. HTML : Saves some 50Kb on every page but portlet look-feel modification is not possible for all (including (Omni)Admin)
      ## Portlet CSS Portlet
       # Set this to true to enable the ability to modify portlet CSS at runtime
       # via the Look and Feel icon. Disabling it can speed up performance.
      portlet.css.enabled=false

      #
      # Set this to false if the system does not use allow users to modify the
      # look and feel.
      #
      look.and.feel.modifiable=true
    5. Javascript: Not needed scripts could be expunged here. But the fattest of them all jQuery is needed almost always
      ## JavaScript
       # Set a list of JavaScript files that will be loaded programmatically in
       # /html/common/themes/top_js.jsp.
       #
       # The ordering of the JavaScript files is important. Specifically, all
       # JQuery scripts should go first.
       #
       # The Liferay scripts are grouped in such a way, that the first grouping
       # denotes utility scripts that are used by the second and third groups. The
       # second grouping denotes utility classes that rely on the first group, but
       # does not rely on the second or third group. The third grouping denotes
       # modules that rely on the first and second group.
       #
       javascript.files= .....
      Setting this will improve download time, but tweaks above are probably unused
       ## JavaScript
       # Set this property to true to load the combined JavaScript files from the
       # property "javascript.files" into one compacted file for faster loading for
       # production. Set this property to false for easier debugging for
       # development. You can also disable fast loading by setting the URL
       # parameter "js_fast_load" to "0".
       javascript.fast.load=true
    6. CSS: Set this property to true to load the theme's merged CSS files for faster loading for production.
      theme.css.fast.load=true
    7. Resources: Get your images and other resources from your personalised theme or even an HTTP server alias like www.liferay.org/resources/ Resources uploaded in Liferay are being served-up from database and will always be slower than using this strategy. especialy for recurring enterprise logo's and all.
    8. Themes: If you need a high performing landing-page and other pages you could consider creating a special theme for these pages.
    9. Velocity Caching: Set this to true in production so that VM templates are cached
      velocity.engine.resource.manager.cache.enabled=true
    10. CSS: Hack removing ALL CSS
      edit templates\portal_normal.vm;
       <head>
           #if ( $is_signed_in )
                #css ($css_main_file) 
           #end
       </head>
  2. Tomcat Configuration
  3. OS settings
  4. MySQL: Links to useful references:
        * A good sample my.cnf: http://www.theadminzone.com/forums/showthread.php?t=8150
        * Optmization, understanding mysql: http://www.mysqlperformanceblog.com/files/presentations/UC2005-Advanced-MySQL-Performance-Optimization.pdf
        * MySQL Performance Tuning Primer Script: http://day32.com/MySQL/
  5.  Memory:
    Memory is one of the first things to look at when you want to optimize performance. If you have any disk swapping, that will have a serious impact on performance. Make sure that your server has an optimal amount of memory and that your JVM is tuned to use it.
    There are three JVM command switches that control the amount of memory it will use.
    -Xms
    -Xmx
    -XX:MaxPermSize
    These three settings control the amount of memory available to the JVM initially, the maximum amount of memory into which the JVM can grow, and the separate area of the heap called Permanent Generation space. 
    Issues with PermGen space can also affect performance. PermGen space contains long-lived classes, anonymous classes and interned Strings. Hibernate, in particular—which Liferay uses extensively—has been known to make use of PermGen space. If you increase the amount of memory available to the JVM, you may want to increase the amount of PermGen space accordingly. 
  6. Portlets: Liferay comes pre-bundled with many portlets which contain a lot of functionality, but not every web site that is running on Liferay needs to use them all. In portlet.xml and liferay-portlet.xml, comment out the ones you are not using. While having a loan calculator, analog clock, or game of hangman available for your users to add to pages is nice, those portlets may be taking up resources that are needed by custom portlets you have written for your site. If you are having performance problems, commenting out some of the unused portlets may give you the performance boost you need.
  7. References/Source
    1. http://www.liferay.com/community/wiki/-/wiki/Main/Performance
    2. http://www.liferay.com/documentation/liferay-portal/5.1/administration/-/ai/performance-tuning;jsessionid=F9EDDE895FF685955600AF21B25C5D43.node-1

      But be careful, these settings need a powerful Application Server.
      Improvement: Approximately 50% faster
      Probably this works also with other Application Servers like Tomcat..
       

Wednesday, April 06, 2011

Liferay Facebook Portlet

http://code.google.com/p/liferay-facebook-portlet/

Liferay Cache

To use liferay cache their is a very good article available at :
http://rutvijshah.wordpress.com/2010/02/27/liferay-cache/

Wednesday, March 30, 2011

Clear Linux Cache

Run 'free' command to get the current memory/cache allocation

### To free pagecache, dentries and inodes:

echo 3 > /proc/sys/vm/drop_caches

Run 'free' command to get the updated status

Thursday, March 17, 2011

Liferay Twitter portlet

https://code.google.com/p/liferay-twitter-portlet/

Friday, February 18, 2011

Liferay 6: Deployment/Undeployment with Ext plugins environment

I have always liked the concept of plug-in in Liferay but using the ext environment as plug-in in Liferay 6 seems to be a little bit painful and time taking. It will need you to restart tomcat a couple of times if you are working in service files. The original  post which i used here for reference documents everything.  I am copying it here so that i can recall it in future. However i am listing below the major steps followed in the original post.
  1. Stop the tomcat.
  2. Remove ext plug-in related jars in @temp folder of your tomcat instance @temp\liferay\com\liferay\portal\deploy\dependencies
  3. Remove ext plug-in related jars from ROOT/WEB-INF/lib/
  4. Remove xml for ext plug-in from ROOT/WEB-INF/
  5. Remove service jar from @tomcat/lib/ext related to plug-in
  6. Start tomcat  and deploy updated plug-in war while tomcat is running, You will see a message like  "You must reboot the server and redeploy all other plugin". 
  7. Now stop the tomcat and restart it again for the global jars to take effect. And you are ready to go
In the original post you will see the bat script which can be quite handy.

Saturday, February 12, 2011

Too Many open files in Alfresco

This is related to facing the situation where alfresco deployed in UNIX environment gives the error of "Too Many Opened Files". This is more often related to File handles and Lucene. UNIX systems is configured by default to allow users a maximum of only 1024 open file handles, which is often not sufficient for the file structure used by the indexes. Thus while setting up Alfresco on UNIX do the following check and configuration to get over this issue.

 Verify that the global settings for maximum number of file handles is large enough.
As a user used to run Alfresco run :
ulimit -n

You can check the number of open files allowed per user with the command

cat /proc/sys/fs/file-max

This gives the number of file handles that can be opened by user at a time.
To increase this number, go to/etc/security/limits.conf file in edit mode and the below lines
username soft nofile 4096
username hard nofile 65536

where username is the name of user to run Alfresco.

And finally restart your Alfresco for the changes to become active.

Check the original issue here.

Other references
http://www.xenoclast.org/doc/benchmark/HTTP-benchmarking-HOWTO/node7.html
http://ironman.darthgibus.net/?tag=too-many-open-files