Showing posts with label performance. Show all posts
Showing posts with label performance. Show all posts

Working with stateless session in hibernate and jpa

When doing heavy read-only operations in with the database it can be a good idea to take advantage of using Hibernate's Stateless Session

As it name indicates this session does not keep state of the entities that it retrieves from the database and so it bypasses the L1 and L2 cache

This can have significant performance impact on heavy DBA read operations (since the state of the entities is not bet tracked)



@Component
@Scope("prototype")
public class SomeJpaService {

public static final int SCROLL_STEP = 1000;

     @PersistenceContext
     private EntityManager entityManager;


    
     public void doInStatelessSession(){

       LOGGER.info("ABOUT to perform Heavy read operation on DB");

       StatelessSession statelessSession = entityManager.unwrap(Session.class).getSessionFactory().openStatelessSession();

        try (ScrollableResults r = statelessSession
                .createQuery("SELECT c FROM Order c")
                .setReadOnly(true)
                .setCacheable(false)
                .scroll()) {// create the scrollable results with a try/close resources block

            while (r.scroll(SCROLL_STEP)) {
                 Order o = (Order) r.get(0);
                //perform some operation on object
              
            }
        }      



        LOGGER.info("FINISHED heavy read operation");

        statelessSession.close();
   }


}

There's however a few caveats with this approach :

  • Collections cannot be fetched on stateless sessions
  • Because of the stateless nature of the session this can only be used on read-only operations

NodeJS, tune or disable HTTP agent pooling

When using NodeJS's HTTP module to query you might end-up having performance problems if you do some heavy HTTP querying.

By default when executing queries using the HTTP module NodeJS will use connection pooling with the maximum number of connection sockets being 5, so if you hit the bottleneck your HTTP queries will lag as they will be queued.

To my knowledge you have 2 options to "counter" this behavior :

  1. Increase the number of http sockets
  2. Disable the HTTP agent per request

1. Increase the number of http sockets

    var http = require('http');

    // increase the maximum number of http connections in the pool
    http.globalAgent.maxSockets = 100;

    //regular http request options
    var options = {
        port: 1337,
        hostname: '127.0.0.1',
        method: 'GET',
        path: '/test'
  };

  // make http query
  var req = http.request(options, function(res) {
       console.log('STATUS: ' + res.statusCode);
       console.log('HEADERS: ' + JSON.stringify(res.headers));
       res.setEncoding('utf8');
       res.on('data', function (chunk) {
          console.log('BODY: ' + chunk);
      });
   });



2.Disable the HTTP agent per request


    var http = require('http');
  
      //regular http request options
      var options = {
         port: 1337,
         hostname: '127.0.0.1',
         method: 'GET',
         path: '/test',
         agent:false //disable the nodejs agent (no connection pooling)
      };

      // make http query
      var req = http.request(options, function(res) {
       console.log('STATUS: ' + res.statusCode);
       console.log('HEADERS: ' + JSON.stringify(res.headers));
       res.setEncoding('utf8');
       res.on('data', function (chunk) {
          console.log('BODY: ' + chunk);
      });
   });

Please be aware that changing this options might have side effects on your host system such as higher memory and bandwidth use so use it wisely

JSF 2 performance improvement on latest release (Mojarra)

According to this blog the latest version of Mojarra JSF (2.1.22) performance should improve dramatically when handling pages with a large quantity of objects (1000+).

jsf-performance-mojarra-improves-dramatically

Always acording to the blog author with the previous version of Mojarra, rendering a page with 1000+ components would take up to 5 times more compared to the other JSF implementation Apache MyFaces.

This is great news and comes as a welcomed improvement!

This improvement comes mainly from the resolution of the bug :

JAVASERVERFACES-2494

OSX show used ports or listening applications with their PID

On OSX you can display applications listening on a given port using the lsof the commands described below will show listening application...