2013-10-07 2 views
0

데이터베이스 : mysql - 테이블 구조입니다. 한 달에 처음으로 사용자 액세스 사이트가 다음 i는 DB에 입력을해야 할 때캐시 검색 결과 구현

------------------------------------------ 
phone_no (This is PK) | month | year 
------------------------------------------ 
varchar(15)    | INT (2) | INT(4) 

이 레코드의 milions을 가지고, 지금, otherise 것도이 목적을보고하고, 일어나지 않을 것입니다. 내 자바 코드는 다음과 같습니다

The VO ----> 
     public class UesrAccessInfo { 
      private String phone_no; 
      private int year; 
      private int month; 
      .. getters and setters ... 
     } 

이제 테이블에 액세스 할 수있는 자바 코드는 다음과 같습니다

/다음 방법은 자바 코드에서 구현 * 어떤 DB를 액세스가 없다가 */

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 for getUesrAccessInfo() in UserAcessHistoryDBUtil class ///////////// 
     String sql = "select month , year from user_access_history where phone_no= ?"; 
     String[][] rs = new MyDBAccessor().getPreparedTable(sql,new String[] { oUesrAccessInfo.getMsisdn() }); 
     if (rs != null && rs.length > 0) { 
     for (String[] item : rs) { 
      oUesrAccessInfo.setMonth(Integer.parseInt(item[0])); 
      oUesrAccessInfo.setMonth(Integer.parseInt(item[1])); 
     } 
     }else{ 
     oUesrAccessInfo.setMonth(0); 
     } 
    } 
    ///////////////////////////////////////////////////////////////// 
    /** 
    * User is already present in database 
    */ 
    if(oUesrAccessInfo.getMonth() != 0){ 

     /** 
     * User has already accessed the 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 is not present in database 
    */ 
    else{ 
     UserAcessHistoryDBUtil.createUserAccessHistory(phone_no,""+ currentMonth, "" + currentYear); 
     request.setAttribute("firstAccessInCurrentMonth", true); 
    } 
} 

그래서, 나는 성능 문제에 직면 해있다. 서버에 메모리 오류가있을 수 있으므로 캐싱을 사용할 수 없습니다.

제안 사항은 성능을 개선하기 위해 mysql에 새로 추가되었습니다.

답변

0

내 제안이 있기 때문에

  • 단지 목적을보고 수행되며 사용자에게 영향을 하지 않을, 왜 run it in a separate thread은하지 않습니다?
  • 일부 TableA에 액세스 할 때마다 삽입을 수행하고 현재 삽입중인 테이블에 대량 삽입을 수행하는 배치 프로세스를 만들 수 있습니다. 적어도 그것은 select 쿼리를 실행하지 않을 것입니다.
+0

귀하의 제안을 주셔서 감사하지만,이에 대한 마지막으로 내가 implementating 오전으로 Ehcache는 –

+0

을 :)하지만 당신은 캐싱을 사용할 수 없습니다 말했다 .. 실제로 그 당시 내 관심사는 따라서 JVM의 메모리를 사용하는 캐시이며, 그에 대한 –

+0

죄송합니다 충돌,하지만 난 ehcache에 의해 또한 외부 메모리를 사용할 수있는 것으로 나타났습니다. 캐싱에 대해 알지 못해 죄송합니다. 최종 구현은 데이터를 가져오고, 업데이트하고, 캐시에 삽입하고, 특정 한도를 초과하면 백엔드 작업이 데이터베이스를 업데이트합니다. :) –