Github user CoderSong2015 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1537#discussion_r183935686
  
    --- Diff: core/conn/odbc/src/odbc/nsksrvr/SrvrConnect.cpp ---
    @@ -530,11 +542,39 @@ static void* SessionWatchDog(void* arg)
                     okToGo = false;
                 }
             }
    -
    -
    -           while(!record_session_done && okToGo)
    -           {
    -                   REPOS_STATS repos_stats = repos_queue.get_task();
    +        vector< vector<string> > query_list;
    +        vector<string> session_start;
    +        vector<string> statement_new_query;
    +        vector<string> session_stat_aggregation;
    +
    +        session_start.push_back("upsert into 
Trafodion.\"_REPOS_\".metric_session_table values");
    +        statement_new_query.push_back("insert into 
Trafodion.\"_REPOS_\".metric_query_table values");
    +        session_stat_aggregation.push_back("insert into 
Trafodion.\"_REPOS_\".metric_query_aggr_table values");
    +
    +        query_list.push_back(session_start);
    +        query_list.push_back(statement_new_query);
    +        query_list.push_back(session_stat_aggregation);
    +
    +        int query_limit = statisticsCacheSize;
    +        int time_limit = aggrInterval;
    +        //0:None 1:update 2:insert/upsert cache limit 3:achieve timeline
    +        int execute_flag = REPOS_EXECUTE_NONE;
    +        clock_t time_start = clock();
    +        clock_t time_end= clock();
    +
    +        REPOS_STATS repos_stats;
    +        while(!record_session_done && okToGo)
    +        {
    +            time_start = clock();
    +            while(repos_queue.isEmpty() && (((time_end = clock()) - 
time_start) / 1000000 < time_limit));
    --- End diff --
    
    Thanks.  I think you are right that spin loops will burn CPU needlessly. As 
for your second point, every mxosrvr will have only  one watchdog thread, and 
only this function will call repos_queue.get_task(). Besides, the whole 
watchdog function  will be locked at the beginning and unlocked at the end so 
that I think it is thread-safe and doesn't need to add lock there. Thanks again 
and look forward to your insight. @DaveBirdsall 


---

Reply via email to