/
PerformanceMemory_p.java
204 lines (182 loc) · 10.8 KB
/
PerformanceMemory_p.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
//PerformaceMemory_p.java
//-----------------------
//part of YaCy
//(C) by Michael Peter Christen; mc@yacy.net
//first published on http://www.anomic.de
//Frankfurt, Germany, 2005
//last major change: 19.09.2005
//
//This program is free software; you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation; either version 2 of the License, or
//(at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//You must compile this file with
//javac -classpath .:../classes PerformanceMemory_p.java
//if the shell's current path is HTROOT
//import java.util.Iterator;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import net.yacy.cora.protocol.Domains;
import net.yacy.cora.protocol.RequestHeader;
import net.yacy.kelondro.index.Cache;
import net.yacy.kelondro.index.RAMIndex;
import net.yacy.kelondro.table.Table;
import net.yacy.kelondro.util.FileUtils;
import net.yacy.kelondro.util.Formatter;
import net.yacy.kelondro.util.MemoryControl;
import de.anomic.search.SearchEventCache;
import de.anomic.search.Switchboard;
import de.anomic.server.serverObjects;
import de.anomic.server.serverSwitch;
public class PerformanceMemory_p {
private static final long KB = 1024;
private static final long MB = 1024 * KB;
private static Map<String, String> defaultSettings = null;
public static serverObjects respond(final RequestHeader header, final serverObjects post, final serverSwitch env) {
// return variable that accumulates replacements
final serverObjects prop = new serverObjects();
if (defaultSettings == null) {
defaultSettings = FileUtils.loadMap(new File(env.getAppPath(), "defaults/yacy.init"));
}
prop.put("gc", "0");
if (post != null) {
if (post.containsKey("gc")) {
System.gc();
prop.put("gc", "1");
}
}
final long memoryFreeNow = MemoryControl.free();
final long memoryFreeAfterInitBGC = Long.parseLong(env.getConfig("memoryFreeAfterInitBGC", "0"));
final long memoryFreeAfterInitAGC = Long.parseLong(env.getConfig("memoryFreeAfterInitAGC", "0"));
final long memoryFreeAfterStartup = Long.parseLong(env.getConfig("memoryFreeAfterStartup", "0"));
final long memoryTotalNow = MemoryControl.total();
final long memoryTotalAfterInitBGC = Long.parseLong(env.getConfig("memoryTotalAfterInitBGC", "0"));
final long memoryTotalAfterInitAGC = Long.parseLong(env.getConfig("memoryTotalAfterInitAGC", "0"));
final long memoryTotalAfterStartup = Long.parseLong(env.getConfig("memoryTotalAfterStartup", "0"));
prop.putNum("memoryMax", MemoryControl.maxMemory / MB);
prop.putNum("memoryAvailAfterStartup", (MemoryControl.maxMemory - memoryTotalAfterStartup + memoryFreeAfterStartup) / MB);
prop.putNum("memoryAvailAfterInitBGC", (MemoryControl.maxMemory - memoryTotalAfterInitBGC + memoryFreeAfterInitBGC) / MB);
prop.putNum("memoryAvailAfterInitAGC", (MemoryControl.maxMemory - memoryTotalAfterInitAGC + memoryFreeAfterInitAGC) / MB);
prop.putNum("memoryAvailNow", (MemoryControl.maxMemory - memoryTotalNow + memoryFreeNow) / MB);
prop.putNum("memoryTotalAfterStartup", memoryTotalAfterStartup / KB);
prop.putNum("memoryTotalAfterInitBGC", memoryTotalAfterInitBGC / KB);
prop.putNum("memoryTotalAfterInitAGC", memoryTotalAfterInitAGC / KB);
prop.putNum("memoryTotalNow", memoryTotalNow / MB);
prop.putNum("memoryFreeAfterStartup", memoryFreeAfterStartup / KB);
prop.putNum("memoryFreeAfterInitBGC", memoryFreeAfterInitBGC / KB);
prop.putNum("memoryFreeAfterInitAGC", memoryFreeAfterInitAGC / KB);
prop.putNum("memoryFreeNow", memoryFreeNow / MB);
prop.putNum("memoryUsedAfterStartup", (memoryTotalAfterStartup - memoryFreeAfterStartup) / KB);
prop.putNum("memoryUsedAfterInitBGC", (memoryTotalAfterInitBGC - memoryFreeAfterInitBGC) / KB);
prop.putNum("memoryUsedAfterInitAGC", (memoryTotalAfterInitAGC - memoryFreeAfterInitAGC) / KB);
prop.putNum("memoryUsedNow", (memoryTotalNow - memoryFreeNow) / MB);
// write table for Table index sizes
Iterator<String> i = Table.filenames();
String filename;
Map<String, String> map;
int p, c = 0;
long mem, totalmem = 0;
while (i.hasNext()) {
filename = i.next();
map = Table.memoryStats(filename);
prop.put("EcoList_" + c + "_tableIndexPath", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
prop.putNum("EcoList_" + c + "_tableSize", map.get("tableSize"));
assert map.get("tableKeyMem") != null : map;
mem = Long.parseLong(map.get("tableKeyMem"));
totalmem += mem;
prop.put("EcoList_" + c + "_tableKeyMem", Formatter.bytesToString(mem));
prop.put("EcoList_" + c + "_tableKeyChunkSize", map.get("tableKeyChunkSize"));
mem = Long.parseLong(map.get("tableValueMem"));
totalmem += mem;
prop.put("EcoList_" + c + "_tableValueMem", Formatter.bytesToString(mem));
prop.put("EcoList_" + c + "_tableValueChunkSize", map.get("tableValueChunkSize"));
c++;
}
prop.put("EcoList", c);
prop.putNum("EcoIndexTotalMem", totalmem / (1024 * 1024d));
// write object cache table
Iterator<Map.Entry<String, RAMIndex>> oi = RAMIndex.objects();
c = 0;
mem = 0;
Map.Entry<String, RAMIndex> oie;
RAMIndex cache;
long hitmem, totalhitmem = 0;
while (oi.hasNext()) {
oie = oi.next();
filename = oie.getKey();
cache = oie.getValue();
prop.put("indexcache_" + c + "_Name", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
hitmem = cache.mem();
totalhitmem += hitmem;
prop.put("indexcache_" + c + "_ChunkSize", cache.row().objectsize);
prop.putNum("indexcache_" + c + "_Count", cache.size());
prop.put("indexcache_" + c + "_NeededMem", cache.size() * cache.row().objectsize);
prop.put("indexcache_" + c + "_UsedMem", hitmem);
c++;
}
prop.put("indexcache", c);
prop.putNum("indexcacheTotalMem", totalhitmem / (1024 * 1024d));
// write object cache table
i = Cache.filenames();
c = 0;
long missmem, totalmissmem = 0;
totalhitmem = 0;
while (i.hasNext()) {
filename = i.next();
map = Cache.memoryStats(filename);
prop.put("ObjectList_" + c + "_objectCachePath", ((p = filename.indexOf("DATA")) < 0) ? filename : filename.substring(p));
// hit cache
hitmem = Long.parseLong(map.get("objectHitMem"));
totalhitmem += hitmem;
prop.put("ObjectList_" + c + "_objectHitChunkSize", map.get("objectHitChunkSize"));
prop.putNum("ObjectList_" + c + "_objectHitCacheCount", map.get("objectHitCacheCount"));
prop.put("ObjectList_" + c + "_objectHitCacheMem", Formatter.bytesToString(hitmem));
prop.putNum("ObjectList_" + c + "_objectHitCacheReadHit", map.get("objectHitCacheReadHit"));
prop.putNum("ObjectList_" + c + "_objectHitCacheReadMiss", map.get("objectHitCacheReadMiss"));
prop.putNum("ObjectList_" + c + "_objectHitCacheWriteUnique", map.get("objectHitCacheWriteUnique"));
prop.putNum("ObjectList_" + c + "_objectHitCacheWriteDouble", map.get("objectHitCacheWriteDouble"));
prop.putNum("ObjectList_" + c + "_objectHitCacheDeletes", map.get("objectHitCacheDeletes"));
prop.putNum("ObjectList_" + c + "_objectHitCacheFlushes", map.get("objectHitCacheFlushes"));
// miss cache
missmem = Long.parseLong(map.get("objectMissMem"));
totalmissmem += missmem;
prop.put("ObjectList_" + c + "_objectMissChunkSize", map.get("objectMissChunkSize"));
prop.putNum("ObjectList_" + c + "_objectMissCacheCount", map.get("objectMissCacheCount"));
prop.putHTML("ObjectList_" + c + "_objectMissCacheMem", Formatter.bytesToString(missmem));
prop.putNum("ObjectList_" + c + "_objectMissCacheReadHit", map.get("objectMissCacheReadHit"));
prop.putNum("ObjectList_" + c + "_objectMissCacheReadMiss", map.get("objectMissCacheReadMiss"));
prop.putNum("ObjectList_" + c + "_objectMissCacheWriteUnique", map.get("objectMissCacheWriteUnique"));
prop.putNum("ObjectList_" + c + "_objectMissCacheWriteDouble", map.get("objectMissCacheWriteDouble"));
prop.putNum("ObjectList_" + c + "_objectMissCacheDeletes", map.get("objectMissCacheDeletes"));
//prop.put("ObjectList_" + c + "_objectMissCacheFlushes", map.get("objectMissCacheFlushes"));
c++;
}
prop.put("ObjectList", c);
prop.putNum("objectCacheStopGrow", Cache.getMemStopGrow() / (1024 * 1024d));
prop.putNum("objectCacheStartShrink", Cache.getMemStartShrink() / (1024 * 1024d));
prop.putNum("objectHitCacheTotalMem", totalhitmem / (1024 * 1024d));
prop.putNum("objectMissCacheTotalMem", totalmissmem / (1024 * 1024d));
// other caching structures
prop.putNum("namecacheHit.size", Domains.nameCacheHitSize());
prop.putNum("namecacheMiss.size", Domains.nameCacheMissSize());
prop.putNum("namecache.noCache", Domains.nameCacheNoCachingListSize());
prop.putNum("blacklistcache.size", Switchboard.urlBlacklist.blacklistCacheSize());
prop.putNum("searchevent.size", SearchEventCache.size());
prop.putNum("searchevent.hit", SearchEventCache.cacheHit);
prop.putNum("searchevent.miss", SearchEventCache.cacheMiss);
prop.putNum("searchevent.insert", SearchEventCache.cacheInsert);
prop.putNum("searchevent.delete", SearchEventCache.cacheDelete);
// return rewrite values for templates
return prop;
}
}