Skip to content

Commit 54a0239

Browse files
author
Bob Simons
committed
v2.20
Former-commit-id: a9a5385df1fe576c89a5a3d0bc39ae2207f849a5 [formerly cfc7175ab3e87358f028b022315eeccaf64184a9] [formerly 30ad470db93301fad6f2a667accba220f20223eb [formerly 9f47d1a59bcb23e9b074968dde31ce75afa6497c]] Former-commit-id: a1b0610dd1cce337b682314e85f5f3976b1873b1 [formerly fbe1d2f4bb405b7dcb34f0a3757db8b307afff42] Former-commit-id: e835167398bc18970028afcb36c526d893d4f8d3 Former-commit-id: 809cc95258ea0a1b558c9699fde9b2925d219c94
1 parent f56c24d commit 54a0239

File tree

7 files changed

+118
-50
lines changed

7 files changed

+118
-50
lines changed

WEB-INF/classes/com/cohort/util/Math2.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class Math2 {
6565
public static long maxSafeMemory = maxMemory * 3L / 4; //75% the max we should consider getting to
6666
public static long dangerousMemory = maxMemory * 9L / 10; //90% this is really bad
6767

68-
public static long alwaysOkayMemoryRequest = maxSafeMemory / 20;
68+
public static long alwaysOkayMemoryRequest = maxSafeMemory / 40;
6969

7070
/**
7171
* These are *not* final so EDStatic can replace them with translated Strings.
@@ -468,7 +468,7 @@ public static void ensureMemoryAvailable(final long nBytes, final String attribu
468468
// even if it was for ERDDAP management (i.e., shooting myself in the foot).
469469

470470
//this is a little risky, but avoids frequent calls to calculate memoryInUse
471-
if (nBytes < alwaysOkayMemoryRequest) //e.g., 8GB -&gt; maxSafe=6GB /20=300MB
471+
if (nBytes < alwaysOkayMemoryRequest) //e.g., 8GB -&gt; maxSafe=6GB /40=150MB
472472
return;
473473

474474
//is this single request by itself too big under any circumstances?

WEB-INF/classes/gov/noaa/pfel/erddap/Erddap.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3610,7 +3610,9 @@ public void doStatus(int language, HttpServletRequest request, HttpServletRespon
36103610
int po = traces.indexOf('\n');
36113611
if (po > 0)
36123612
sb.append(traces.substring(0, po + 1));
3613-
sb.append(EDStatic.gcCalled + " gc calls and " + EDStatic.requestsShed + " requests shed since last major LoadDatasets\n");
3613+
sb.append(EDStatic.gcCalled + " gc calls, " +
3614+
EDStatic.requestsShed + " requests shed, and " +
3615+
EDStatic.dangerousMemoryEmails + " dangerousMemoryEmails since last major LoadDatasets\n");
36143616
sb.append(Math2.memoryString() + " " + Math2.xmxMemoryString() + "\n\n");
36153617

36163618
EDStatic.addCommonStatistics(sb);

WEB-INF/classes/gov/noaa/pfel/erddap/LoadDatasets.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ public void run() {
10551055
//reset since last majorReload
10561056
EDStatic.gcCalled = 0;
10571057
EDStatic.requestsShed = 0;
1058+
EDStatic.dangerousMemoryEmails = 0;
10581059
EDStatic.dangerousMemoryFailures = 0;
10591060
EDStatic.tooManyRequests = 0;
10601061

@@ -1077,7 +1078,9 @@ public void run() {
10771078
if (threadSummary != null)
10781079
contentSB.append(threadSummary + "\n");
10791080

1080-
contentSB.append(EDStatic.gcCalled + " gc calls and " + EDStatic.requestsShed + " requests shed since last major LoadDatasets\n");
1081+
contentSB.append(EDStatic.gcCalled + " gc calls, " +
1082+
EDStatic.requestsShed + " requests shed, and " +
1083+
EDStatic.dangerousMemoryEmails + " dangerousMemoryEmails since last major LoadDatasets\n");
10811084
contentSB.append(Math2.memoryString() + " " + Math2.xmxMemoryString() + "\n\n");
10821085
contentSB.append(stars + "\nTallied Usage Information\n\n");
10831086
contentSB.append(EDStatic.tally.toString(50));
@@ -1215,7 +1218,9 @@ public void run() {
12151218
if (threadSummary != null)
12161219
sb.append(threadSummary + "\n");
12171220

1218-
sb.append(EDStatic.gcCalled + " gc calls and " + EDStatic.requestsShed + " requests shed since last major LoadDatasets\n");
1221+
sb.append(EDStatic.gcCalled + " gc calls, " +
1222+
EDStatic.requestsShed + " requests shed, and " +
1223+
EDStatic.dangerousMemoryEmails + " dangerousMemoryEmails since last major LoadDatasets\n");
12191224
sb.append(Math2.memoryString() + " " + Math2.xmxMemoryString() + "\n\n");
12201225
EDStatic.addCommonStatistics(sb);
12211226
sb.append(EDStatic.tally.toString("Large Request, IP address (since last Major LoadDatasets)", 50));

WEB-INF/classes/gov/noaa/pfel/erddap/util/EDStatic.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public class EDStatic {
186186
* <br>2.17 released on 2022-02-16
187187
* <br>2.18 released on 2022-02-23
188188
* <br>2.19 released on 2022-09-10
189-
* <br>2.20 released on 2022-09-??
189+
* <br>2.20 released on 2022-09-30
190190
*
191191
* For master branch releases, this will be a floating point
192192
* number with 2 decimal digits, with no additional text.
@@ -265,6 +265,7 @@ public class EDStatic {
265265
public static int touchThreadSucceededDistributionTotal[]= new int[String2.TimeDistributionSize];
266266
public static volatile int gcCalled = 0; //since last Major LoadDatasets
267267
public static volatile int requestsShed = 0; //since last Major LoadDatasets
268+
public static volatile int dangerousMemoryEmails = 0; //since last Major LoadDatasets
268269
public static volatile int dangerousMemoryFailures = 0; //since last Major LoadDatasets
269270
public static StringBuffer suggestAddFillValueCSV = new StringBuffer(); //EDV constructors append message here //thread-safe but probably doesn't need to be
270271

@@ -288,12 +289,12 @@ public class EDStatic {
288289
public final static String ipAddressUnknown = "(unknownIPAddress)";
289290
public final static ConcurrentHashMap<String,IntArray> ipAddressQueue = new ConcurrentHashMap(); //ipAddress -> list of request#
290291
public final static int DEFAULT_ipAddressMaxRequestsActive = 2; //in datasets.xml
291-
public final static int DEFAULT_ipAddressMaxRequests = 7; //in datasets.xml //more requests will see Too Many Requests error. This must be at least 6 because browsers make up to 6 simultaneous requests. This can't be >1000.
292+
public final static int DEFAULT_ipAddressMaxRequests = 15; //in datasets.xml //more requests will see Too Many Requests error. This must be at least 6 because browsers make up to 6 simultaneous requests. This can't be >1000.
292293
public final static String DEFAULT_ipAddressUnlimited = ", " + ipAddressUnknown;
293294
public static int ipAddressMaxRequestsActive = DEFAULT_ipAddressMaxRequestsActive; //in datasets.xml
294295
public static int ipAddressMaxRequests = DEFAULT_ipAddressMaxRequests; //in datasets.xml //more requests will see Too Many Requests error. This must be at least 6 because browsers make up to 6 simultaneous requests.
295296
public static HashSet<String> ipAddressUnlimited = //in datasets.xml //read only. New one is swapped into place. You can add and remove addresses as needed.
296-
new HashSet<String>(String2.toArrayList(StringArray.fromCSVNoBlanks(EDStatic.DEFAULT_ipAddressUnlimited).toArray()));
297+
new HashSet<String>(String2.toArrayList(StringArray.fromCSVNoBlanks(DEFAULT_ipAddressUnlimited).toArray()));
297298
public static int tooManyRequests = 0; //nRequests exceeding ipAddressMaxRequests, since last major datasets reload
298299
public final static String translationDisclaimer =
299300
//from https://cloud.google.com/translate/attribution
@@ -2514,7 +2515,7 @@ else if ((upo != -1 && upo != 4) ||
25142515
convertUnitsNotesAr = getNotNothingString(messagesAr, "convertUnitsNotes", errorInMethod);
25152516
for (int tl = 0; tl < nLanguages; tl++)
25162517
convertUnitsNotesAr[tl] = convertUnitsNotesAr[tl]
2517-
.replace("&unitsStandard;", EDStatic.units_standard);
2518+
.replace("&unitsStandard;", units_standard);
25182519
convertUnitsServiceAr = getNotNothingString(messagesAr, "convertUnitsService", errorInMethod);
25192520
convertURLsAr = getNotNothingString(messagesAr, "convertURLs", errorInMethod);
25202521
convertURLsIntroAr = getNotNothingString(messagesAr, "convertURLsIntro", errorInMethod);
@@ -3497,7 +3498,7 @@ else if ((upo != -1 && upo != 4) ||
34973498

34983499
WMSNotesAr = getNotNothingString(messagesAr, "WMSNotes", errorInMethod);
34993500
for (int tl = 0; tl < nLanguages; tl++)
3500-
EDStatic.WMSNotesAr[tl] = EDStatic.WMSNotesAr[tl].replace( "&WMSSEPARATOR;", Character.toString(EDD.WMS_SEPARATOR));
3501+
WMSNotesAr[tl] = WMSNotesAr[tl].replace( "&WMSSEPARATOR;", Character.toString(EDD.WMS_SEPARATOR));
35013502

35023503
yourEmailAddressAr = getNotNothingString(messagesAr, "yourEmailAddress", errorInMethod);
35033504
zoomInAr = getNotNothingString(messagesAr, "zoomIn", errorInMethod);
@@ -4677,8 +4678,8 @@ public static void addCommonStatistics(StringBuilder sb) {
46774678
sb.append(String2.getTimeDistributionStatistics(touchThreadSucceededDistributionTotal)); sb.append('\n');
46784679
sb.append('\n');
46794680

4680-
sb.append(EDStatic.tally.toString("Language (since last daily report)", 50)); //added v2.15
4681-
sb.append(EDStatic.tally.toString("Language (since startup)", 50));
4681+
sb.append(tally.toString("Language (since last daily report)", 50)); //added v2.15
4682+
sb.append(tally.toString("Language (since startup)", 50));
46824683

46834684
sb.append(SgtMap.topographyStats() + "\n");
46844685
sb.append(GSHHS.statsString() + "\n");
@@ -4956,15 +4957,15 @@ public static void sendHttpUnauthorizedError(int language, int requestNumber, St
49564957
if (datasetID != null && datasetID.length() > 0)
49574958
message = MessageFormat.format(
49584959
graphsAccessibleToPublic?
4959-
EDStatic.notAuthorizedForDataAr[language] :
4960-
EDStatic.notAuthorizedAr[language],
4960+
notAuthorizedForDataAr[language] :
4961+
notAuthorizedAr[language],
49614962
loggedInAsHttps.equals(loggedInAs)? "" : loggedInAs,
49624963
datasetID);
49634964

49644965
lowSendError(requestNumber, response, HttpServletResponse.SC_UNAUTHORIZED, message);
49654966

49664967
} catch (Throwable t2) {
4967-
EDStatic.rethrowClientAbortException(t2); //first thing in catch{}
4968+
rethrowClientAbortException(t2); //first thing in catch{}
49684969
String2.log("Error in sendHttpUnauthorizedError for request #" + requestNumber + ":\n" +
49694970
(message == null? "" : message + "\n") +
49704971
MustBe.throwableToString(t2));
@@ -5984,7 +5985,7 @@ public static String passThroughJsonpQuery(int language, HttpServletRequest requ
59845985
return "";
59855986
String functionName = jsonp.substring(7); //it will be because it starts with .jsonp=
59865987
if (!String2.isJsonpNameSafe(functionName))
5987-
throw new SimpleException(EDStatic.bilingual(language,
5988+
throw new SimpleException(bilingual(language,
59885989
errorJsonpFunctionNameAr[0],
59895990
errorJsonpFunctionNameAr[language]));
59905991
return ".jsonp=" + SSR.minimalPercentEncode(functionName) + "&";
@@ -6152,7 +6153,7 @@ public static String nMatchingDatasetsHtml(int language, int nMatches, int page,
61526153
"...\n");
61536154
if (page >= 3) sb.append(
61546155
url0 + (page>2? prev : bmrk) + url1 + (page - 1) + url2 + (page - 1) + url3);
6155-
sb.append("&nbsp;" + page + "&nbsp;(" + EDStatic.nMatchingCurrentAr[language] + ")&nbsp;\n"); //always show current page
6156+
sb.append("&nbsp;" + page + "&nbsp;(" + nMatchingCurrentAr[language] + ")&nbsp;\n"); //always show current page
61566157
if (page <= lastPage - 2) sb.append(
61576158
url0 + (page<lastPage-1? next : bmrk) + url1 + (page + 1) + url2 + (page + 1) + url3);
61586159
if (page <= lastPage - 3) sb.append(
@@ -6438,6 +6439,7 @@ public static boolean shedThisRequest(int language, int requestNumber, HttpServl
64386439
//if memory use is dangerously high and I haven't reported this incident, report it
64396440
if (inUse >= Math2.dangerousMemory && lastActiveRequestReportTime == 0) {
64406441
lastActiveRequestReportTime = System.currentTimeMillis(); //do first so other threads don't also report this
6442+
dangerousMemoryEmails++;
64416443
activeRequests.remove(requestNumber + ""); //don't blame this request
64426444
String activeRequestLines[] = activeRequests.values().toArray(new String[0]);
64436445
Arrays.sort(activeRequestLines);
@@ -6449,7 +6451,7 @@ public static boolean shedThisRequest(int language, int requestNumber, HttpServl
64496451
"Active requests:\n" +
64506452
String2.toNewlineString(activeRequestLines);
64516453
String2.log(report);
6452-
email(EDStatic.emailEverythingToCsv, "Dangerously High Memory Use!!!", report);
6454+
email(emailEverythingToCsv, "Dangerously High Memory Use!!!", report);
64536455
}
64546456

64556457
//memory use is too high, so shed this request
@@ -6577,7 +6579,7 @@ public static void sendError(int requestNumber, HttpServletRequest request,
65776579

65786580
} else if (tError.indexOf(Math2.memoryArraySize.substring(0, 25)) >= 0) {
65796581
errorNo = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE; //http error 413 (the old name for Payload Too Large), although it could be other user's requests that are too large
6580-
String ipAddress = EDStatic.getIPAddress(request);
6582+
String ipAddress = getIPAddress(request);
65816583
tally.add("OutOfMemory (Array Size), IP Address (since last Major LoadDatasets)", ipAddress);
65826584
tally.add("OutOfMemory (Array Size), IP Address (since last daily report)", ipAddress);
65836585
tally.add("OutOfMemory (Array Size), IP Address (since startup)", ipAddress);
@@ -6586,15 +6588,15 @@ public static void sendError(int requestNumber, HttpServletRequest request,
65866588
tError.indexOf(Math2.memoryThanCurrentlySafe.substring(0, 25)) >= 0) { //!!! TROUBLE: but that matches memoryThanSafe (in English) too!
65876589
errorNo = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE; //http error 413 (the old name for Payload Too Large), although it could be other user's requests that are too large
65886590
dangerousMemoryFailures++;
6589-
String ipAddress = EDStatic.getIPAddress(request);
6591+
String ipAddress = getIPAddress(request);
65906592
tally.add("OutOfMemory (Too Big), IP Address (since last Major LoadDatasets)", ipAddress);
65916593
tally.add("OutOfMemory (Too Big), IP Address (since last daily report)", ipAddress);
65926594
tally.add("OutOfMemory (Too Big), IP Address (since startup)", ipAddress);
65936595

65946596
} else if (tErrorLC.indexOf(Math2.memory) >= 0) {
65956597
//catchall for remaining memory problems
65966598
errorNo = HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE; //http error 413 (the old name for Payload Too Large)
6597-
String ipAddress = EDStatic.getIPAddress(request);
6599+
String ipAddress = getIPAddress(request);
65986600
tally.add("OutOfMemory (Way Too Big), IP Address (since last Major LoadDatasets)", ipAddress);
65996601
tally.add("OutOfMemory (Way Too Big), IP Address (since last daily report)", ipAddress);
66006602
tally.add("OutOfMemory (Way Too Big), IP Address (since startup)", ipAddress);
@@ -6658,8 +6660,8 @@ public static void lowSendError(int requestNumber, HttpServletResponse response,
66586660
//because any of these errors could be in a script
66596661
//and it's good to slow the script down (prevent 100 bad requests/second)
66606662
//and if it's a human they won't even notice a short delay
6661-
if (EDStatic.slowDownTroubleMillis > 0)
6662-
Math2.sleep(EDStatic.slowDownTroubleMillis);
6663+
if (slowDownTroubleMillis > 0)
6664+
Math2.sleep(slowDownTroubleMillis);
66636665

66646666
//put the HTTP status code name at the start of the message (from Wikipedia list
66656667
// https://en.wikipedia.org/wiki/List_of_HTTP_status_codes
@@ -6743,7 +6745,7 @@ public static void testUpdateUrls() throws Exception {
67436745
add.set( "b", "http://www.whoi.edu"); //purposely out-of-date
67446746
add.set( "ten", 10.0);
67456747
add.set( "sourceUrl", "http://coastwatch.pfel.noaa.gov"); //purposely out-of-date
6746-
EDStatic.updateUrls(source, add);
6748+
updateUrls(source, add);
67476749
String results = add.toString();
67486750
String expected =
67496751
" a=https://coastwatch.pfeg.noaa.gov\n" +
@@ -6758,7 +6760,7 @@ public static void testUpdateUrls() throws Exception {
67586760
add.set("b", "http://www.whoi.edu");
67596761
add.set("nine", 9.0);
67606762
add.set("sourceUrl", "http://coastwatch.pfel.noaa.gov");
6761-
EDStatic.updateUrls(null, add);
6763+
updateUrls(null, add);
67626764
results = add.toString();
67636765
expected =
67646766
" a=https://coastwatch.pfeg.noaa.gov\n" +

0 commit comments

Comments
 (0)