@@ -41,11 +41,8 @@ public class SystemCleanUp implements Runnable, ManagedProcess {
4141 private volatile boolean f = true ;
4242 CountDownLatch latch ;
4343 private final static Logger logger = LoggerFactory .getLogger (SystemCleanUp .class );
44- private static final int CLEANUP_TIMEOUT = 3000 ;
4544 public static final int DATA_RETRIEVED_PRIORITY = 6 ;
4645 public static final int INDEX_RETRIEVED_PRIORITY = 9 ;
47- private static final int CLEANUP_PROTECTION_THR = 1000 ;
48- private static final int IX_CLEANUP_PROTECTION_THR = 5000 ;
4946
5047 public void run () {
5148 Thread .currentThread ().setName ("interference-cleanup-thread" );
@@ -58,7 +55,7 @@ public void run () {
5855 }
5956
6057 try {
61- Thread .sleep (CLEANUP_TIMEOUT );
58+ Thread .sleep (Config . getConfig (). CLEANUP_TIMEOUT );
6259 } catch (InterruptedException e ) {
6360 e .printStackTrace ();
6461 }
@@ -74,7 +71,6 @@ public void stop() throws InterruptedException{
7471 }
7572
7673 private void cleanUpFrames () {
77-
7874 Metrics .get ("systemCleanUp" ).start ();
7975 int i = 0 ;
8076 int d = 0 ;
@@ -87,9 +83,9 @@ private void cleanUpFrames() {
8783 for (Object entry : Instance .getInstance ().getFramesMap ().entrySet ()) {
8884 final FrameData f = (FrameData ) ((DataChunk ) ((Map .Entry ) entry ).getValue ()).getEntity ();
8985 final long frameAmount = f .getDataObject ().getFrameAmount ();
90- if (f .getDataFile ().isData ()) {
86+ if (f .getDataFile ().isData () && cleanupDataEnabled () ) {
9187 f .decreasePriority ();
92- if (f .isSynced () && f .getObjectId () > 999 && f .getPriority () == 0 && frameAmount > CLEANUP_PROTECTION_THR ) {
88+ if (f .isSynced () && f .getObjectId () > 999 && f .getPriority () == 0 && frameAmount > Config . getConfig (). CLEANUP_PROTECTION_THR ) {
9389 if (f .clearFrame ()) {
9490 d ++;
9591 }
@@ -98,9 +94,9 @@ private void cleanUpFrames() {
9894 d_ ++;
9995 }
10096 }
101- if (f .getDataFile ().isIndex ()) {
97+ if (f .getDataFile ().isIndex () && cleanupIndxEnabled () ) {
10298 f .decreasePriority ();
103- if (f .isSynced () && f . getObjectId () > 999 && f . getPriority () == 0 && frameAmount > IX_CLEANUP_PROTECTION_THR ) {
99+ if (f .getPriority () == 0 && frameAmount > Config . getConfig (). IX_CLEANUP_PROTECTION_THR ) {
104100 if (f .clearFrame ()) {
105101 x ++;
106102 }
@@ -109,8 +105,8 @@ private void cleanUpFrames() {
109105 x_ ++;
110106 }
111107 }
112- if (f .getDataFile ().isTemp ()) {
113- if (f . isSynced () && f . getObjectId () > 999 && frameAmount > CLEANUP_PROTECTION_THR ) {
108+ if (f .getDataFile ().isTemp () && cleanupTempEnabled () ) {
109+ if (frameAmount > Config . getConfig (). CLEANUP_PROTECTION_THR ) {
114110 if (f .clearFrame ()) {
115111 i ++;
116112 }
@@ -119,8 +115,8 @@ private void cleanUpFrames() {
119115 i_ ++;
120116 }
121117 }
122- if (f .getDataFile ().isUndo ()) {
123- if (f .isSynced () && frameAmount > CLEANUP_PROTECTION_THR ) {
118+ if (f .getDataFile ().isUndo () && cleanupUndoEnabled () ) {
119+ if (f .isSynced () && frameAmount > Config . getConfig (). CLEANUP_PROTECTION_THR ) {
124120 if (f .clearFrame ()) {
125121 u ++;
126122 }
@@ -148,4 +144,32 @@ public static void forceCleanUp() {
148144 }
149145 }
150146 }
147+
148+ private boolean cleanupDataEnabled () {
149+ final long maxmem = Runtime .getRuntime ().maxMemory ();
150+ final long alloc = Runtime .getRuntime ().totalMemory ();
151+ final long allocpc = alloc * 100 / maxmem ;
152+ return allocpc > Config .getConfig ().HEAP_USE_THR_DATA ;
153+ }
154+
155+ private boolean cleanupIndxEnabled () {
156+ final long maxmem = Runtime .getRuntime ().maxMemory ();
157+ final long alloc = Runtime .getRuntime ().totalMemory ();
158+ final long allocpc = alloc * 100 / maxmem ;
159+ return allocpc > Config .getConfig ().HEAP_USE_THR_INDX ;
160+ }
161+
162+ private boolean cleanupUndoEnabled () {
163+ final long maxmem = Runtime .getRuntime ().maxMemory ();
164+ final long alloc = Runtime .getRuntime ().totalMemory ();
165+ final long allocpc = alloc * 100 / maxmem ;
166+ return allocpc > Config .getConfig ().HEAP_USE_THR_UNDO ;
167+ }
168+
169+ private boolean cleanupTempEnabled () {
170+ final long maxmem = Runtime .getRuntime ().maxMemory ();
171+ final long alloc = Runtime .getRuntime ().totalMemory ();
172+ final long allocpc = alloc * 100 / maxmem ;
173+ return allocpc > Config .getConfig ().HEAP_USE_THR_TEMP ;
174+ }
151175}
0 commit comments