java - cache search result implementation -
database: mysql -- table structure is.
------------------------------------------ phone_no (this pk) | month | year ------------------------------------------ varchar(15) | int (2) | int(4)
this has milions of records, when user access site first time in month, have make entry in db, otherise nothing happen, reporting purpose. java code is:
the vo ----> public class uesraccessinfo { private string phone_no; private int year; private int month; .. getters , setters ... }
now java code access table :
/* following methods implemented in java code, no db accesses there */
string phone_no = getphonenumber(); int currentmonth = getcurmonth(); int currentyear = getcuryear(; if (phone_no == null ) { request.setattribute("firstaccessincurrentmonth", false); } else{ uesraccessinfo ouesraccessinfo = new uesraccessinfo(); ouesraccessinfo.setphone_no(phone_no); useracesshistorydbutil.getuesraccessinfo(ouesraccessinfo); //////////// code getuesraccessinfo() in useracesshistorydbutil class ///////////// string sql = "select month , year user_access_history phone_no= ?"; string[][] rs = new mydbaccessor().getpreparedtable(sql,new string[] { ouesraccessinfo.getmsisdn() }); if (rs != null && rs.length > 0) { (string[] item : rs) { ouesraccessinfo.setmonth(integer.parseint(item[0])); ouesraccessinfo.setmonth(integer.parseint(item[1])); } }else{ ouesraccessinfo.setmonth(0); } } ///////////////////////////////////////////////////////////////// /** * user present in database */ if(ouesraccessinfo.getmonth() != 0){ /** * user has accessed site in current month */ if(ouesraccessinfo.getyear() == currentyear && ouesraccessinfo.getmonth() == currentmonth){ request.setattribute("firstaccessincurrentmonth", false); } else{ useracesshistorydbutil.updateuseraccesshistory(phone_no, ""+ currentmonth, "" + currentyear); request.setattribute("firstaccessincurrentmonth", true); } } /** * user not present in database */ else{ useracesshistorydbutil.createuseraccesshistory(phone_no,""+ currentmonth, "" + currentyear); request.setattribute("firstaccessincurrentmonth", true); } }
so, here facing performance issue. cant use caching, there can out of memory error in server.
any suggestion , improve performance, new in mysql.
my suggestions
- since done reporting purpose , not going affect user, why don't run in separate thread?
- you insert each access tablea , create batch process bulk insert table inserting into. @ least avoid running select query.
Comments
Post a Comment