@@ -864,9 +864,9 @@ PDC_region_cache_clock_cycle(void *ptr)
864864 pdc_obj_cache * obj_cache , * obj_cache_iter ;
865865 struct timeval current_time ;
866866 struct timeval finish_time ;
867- int nflush = 0 ;
868- double flush_frequency_s = PDC_CACHE_FLUSH_TIME_INT , elapsed_time = 0.0 ;
869- int server_rank = 0 ;
867+ int nflush = 0 ;
868+ int flush_frequency_s = PDC_CACHE_FLUSH_TIME_INT , elapsed_time = 0.0 ;
869+ int server_rank = 0 ;
870870
871871 char * p = getenv ("PDC_SERVER_CACHE_FLUSH_FREQUENCY_S" );
872872 if (p != NULL )
@@ -876,30 +876,15 @@ PDC_region_cache_clock_cycle(void *ptr)
876876 obj_cache_iter = NULL ;
877877 }
878878 while (1 ) {
879- nflush = 0 ;
880- usleep (1000 );
881879 pthread_mutex_lock (& pdc_cache_mutex );
882880 if (!pdc_recycle_close_flag ) {
883881 pthread_mutex_lock (& pdc_obj_cache_list_mutex );
884882 gettimeofday (& current_time , NULL );
885883 obj_cache_iter = obj_cache_list ;
886- nflush = 0 ;
884+ nflush = 0 ;
887885 while (obj_cache_iter != NULL ) {
888886 obj_cache = obj_cache_iter ;
889- // flush every *flush_frequency_s seconds
890- if (obj_cache -> timestamp .tv_sec > 0 )
891- elapsed_time = current_time .tv_sec - obj_cache_list -> timestamp .tv_sec ;
892- if (elapsed_time >= flush_frequency_s ) {
893- /* char tmbuf[64]; */
894- /* strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S",
895- * localtime(&obj_cache->timestamp.tv_sec)); */
896- /* fprintf(stderr, "Previous %s\n", tmbuf); */
897- /* strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", localtime(¤t_time.tv_sec)); */
898- /* fprintf(stderr, "Current %s\n", tmbuf); */
899- nflush += PDC_region_cache_flush_by_pointer (obj_cache -> obj_id , obj_cache );
900- // Update latest flush time
901- gettimeofday (& obj_cache_list -> timestamp , NULL );
902- }
887+ nflush += PDC_region_cache_flush_by_pointer (obj_cache -> obj_id , obj_cache );
903888 obj_cache_iter = obj_cache_iter -> next ;
904889 }
905890 if (nflush > 0 ) {
@@ -913,13 +898,18 @@ PDC_region_cache_clock_cycle(void *ptr)
913898 "==PDC_SERVER[%d]: %s, flushed %d regions to storage (full/every %.0fs), took %.4fs\n" ,
914899 server_rank , __func__ , nflush , flush_frequency_s , elapsed_time );
915900 }
901+ else
902+ fprintf (stderr , "==PDC_SERVER[%d]: %s, no cached data flushed\n" , server_rank , __func__ );
903+
916904 pthread_mutex_unlock (& pdc_obj_cache_list_mutex );
917905 }
918906 else {
919907 pthread_mutex_unlock (& pdc_cache_mutex );
920908 break ;
921909 }
910+
922911 pthread_mutex_unlock (& pdc_cache_mutex );
912+ sleep (flush_frequency_s );
923913 }
924914 return 0 ;
925915}
0 commit comments