Servlet doesn't load Cache on startup

User dfeb81947d

11-08-2005 08:31:17

Dear Support,





I have problem with loading the cache of the structure table on startup of the Servlet.


The code is executed, but it acts as if it doesn't do anything:


Code:
private void initSSSearch() {


   /*


   initialisation of the connection to the database and of the Structure Search Objet


   */


   // creation of a new Search Object


   Searcher searcher = new Searcher();


   try {


      //Connection to the database


      GlobalObjectBean.connect();         searcher.setSearcher(GlobalObjectBean.getSearchTable());


      searcher.search("O1FBrClPS1ClClNcNn", SearchConstants.SUBSTRUCTURE,0.0f);


   } catch (Exception e) {


      e.printStackTrace();


   }


}






The class GlobalObjectBean contains the parameters of the connection and an Active ConnexionHandler.


The class that makes the search is Searcher and it uses the connection from GlobalObjectBeans.





I wonder if I need to declare the Search as global Variable in the Servlet SSSearch instead of creating a new Object each time doPost or doGet is used?


Code:
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


   String molfile = req.getParameter("molfile");


   String table = req.getParameter("structuretable");


   String mode = req.getParameter("searchmode");


   String treshold = req.getParameter("treshold");


   Searcher search = new Searcher();


   search.setSearcher(table);


   try {


      search.search(molfile, Integer.parseInt(mode), Float.parseFloat(treshold));


      if (search.getSearcher().getResultCount()>0) {


         for (i=0;i<search.getSearcher().getResultCount();i++) {


            System.out.println(search.getSearcher().getResult(i));


         }         


      } else {


         System.out.println("NO MOLECULE!");


      }


      search.setJChemSearcher(null);


   } catch (SearchError se) {


      cat.error("Search Error: "+se.getMessage());


      se.printStackTrace();


   }   


}


What do you think of it?





Could you give me some advice to improve the speed of the execution of the search.





Thank you very much for your help.





Warmest Regards,


Jacques

ChemAxon 9c0afc9aaf

11-08-2005 09:32:53

Hi Jacques,





Why do you think the cache is not loaded ?


Please uncomment the following line in your code and send me the output:





//searcher.setInfoToStdError(true);





It should not be a problem if you create a new JChemSearch object for each search.


Actually you must create a new JChemSearch object at least for each session, otherwise you will have problems with multiple users.





It's also a bad practice to use a single ConnectionHandler (and therefore a single Connection) object for the whole application.


The Connection is not thread safe, so every session should have its own connection to the database.


(you may create a new one for every session, or use a connection pool)





Best regards,





Szilard

User dfeb81947d

11-08-2005 10:00:56

Thank you for your fast answer,





Here are the output





on loading the server, the servlet execute a first substructure search
log wrote:
Thu Aug 11 11:46:40 CEST 2005


Search mode: SUBSTRUCTURE


Structure table: AUREUS.STRUCT_CSMOL


Query: nNcNClClS1OFBrClP1


Screened: 0


Hits: 0


Cache loading: 76266 ms


Cache size (this table / total): 41.66 / 41.66 MBytes


Total time: 390 ms Screening: 47 ms


Processing threads: 2


Current / peak / maximum searches per minute: 1 / 1 / Unlimited
Then a user make a first structure search
log wrote:



Thu Aug 11 11:49:26 CEST 2005


Search mode: SUBSTRUCTURE


Structure table: AUREUS.STRUCT_CSMOL_NOPEPT


Query: [#6]-c1ccc2c(-[#6])ccc(-[#6])c2c1


Screened: 3365


Hits: 2


Cache loading: 78718 ms


Cache size (this table / total): 35.03 / 76.68 MBytes


Total time: 5907 ms Screening: 63 ms


Processing threads: 2


Current / peak / maximum searches per minute: 1 / 1 / Unlimited
and after the first structure search the cache is really loaded.
log wrote:
Thu Aug 11 11:51:56 CEST 2005


Search mode: SUBSTRUCTURE


Structure table: AUREUS.STRUCT_CSMOL_NOPEPT


Query: [#6]NCC(=O)N[#6]


Screened: 18381


Hits: 17571


Total time: 5578 ms Screening: 46 ms


Processing threads: 2


Current / peak / maximum searches per minute: 1 / 1 / Unlimited
STRUCT_CSMOL is the physical table


STRUCT_CSMOL_NOPEPT is a view...


user can research on the table or on a view...


Do I have to load in the cache the table and the views?





By the way... I use this servlet throw other application via a http request


(http://host:8080/servlet/execute?arg1=mol&arg2=mode ...)


So I don't have any session, since this is not a web application. Do I need to create a Connection to the database for each doPost all the same?





Thank you for your help.


Kind regards


Jacques

User dfeb81947d

11-08-2005 10:12:44

If I have three structure table and can make structure search upon them...


Can I load in cache the three table or, there is only one cache, and the structures will be loaded for each table when a structure is being searched?


Are there only one cache, or each table has its own cache?





thank you so far


Best regards


Jacques

ChemAxon 9c0afc9aaf

11-08-2005 11:27:57

Hi,
Quote:
So I don't have any session, since this is not a web application. Do I need to create a Connection to the database for each doPost all the same?
Crating a new connection for each request and closing it after serving the request would work well.


You may save the time of creation a new connection for every search by recycling a fixed number of Connections using a connection pool.





If you want to load multiple tables/views into memory, you should run a search on each table/view. Each will have their own cache object.








Best regards,





Szilard