Skip to content

Commit

Permalink
Update Healthcheck and add javadoc (#9542)
Browse files Browse the repository at this point in the history
* Update Healthcheck and add javadoc

* sebd requests; improve javadoc

* add more javadoc
  • Loading branch information
SteVio89 authored Oct 26, 2023
1 parent 5320c0b commit 5c777a4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ public void setPostDisambiguationChunker(Chunker chunker) {
/**
* Create a shared instance of JLanguageTool to use in rules for further processing
* Instances are shared by Language
* As this is a shared instance, do not modify (add or remove) any rules or filters.
* The alternative to disabling/enabling rules is to select the desired rules from getAllActiveRules(), and run them separately with rule.match(analizedSentence).
*
* Do not call this in a static block or to initialize a static JLanguageTool field in rules or filters classes, this could lead to a deadlock during initialization.
*
* @since 6.1
* @return a shared JLanguageTool instance for this language
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ public void handle(HttpExchange httpExchange) throws IOException {
// healthcheck should come before other limit checks (requests per time etc.), to be sure it works:
String pathWithoutVersion = path.substring("/v2/".length());
if (pathWithoutVersion.equals("healthcheck")) {
if (workQueueFull(httpExchange, parameters, "Healthcheck failed: There are currently too many parallel requests.")) {
String message = "Healthcheck failed: There are currently too many parallel requests.";
if (workQueueFull(httpExchange, parameters, message) || textCheckerQueueFull(httpExchange, message)) {
ServerMetricsCollector.getInstance().logFailedHealthcheck();
return;
} else {
Expand Down Expand Up @@ -323,6 +324,14 @@ private boolean workQueueFull(HttpExchange httpExchange, Map<String, String> par
return false;
}

private boolean textCheckerQueueFull(HttpExchange httpExchange, String response) throws IOException {
if(textCheckerV2.checkerQueueAlmostFull()) {
sendError(httpExchange, HTTP_UNAVAILABLE, "Error: " + response);
return true;
}
return false;
}

@NotNull
private String getTextOrDataSizeMessage(Map<String, String> parameters) {
String text = parameters.get("text");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,19 @@ void checkText(AnnotatedText aText, HttpExchange httpExchange, Map<String, Strin

}

public boolean checkerQueueAlmostFull() {
if (this.executorService instanceof ThreadPoolExecutor) {
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) this.executorService;
int maxQueueSize = config.getTextCheckerQueueSize();
int queuesize = threadPoolExecutor.getQueue().size();

This comment has been minimized.

Copy link
@danielnaber

danielnaber Oct 26, 2023

Member

queuesize -> queueSize

if (queuesize > maxQueueSize/2) { //should not happen in normal cases (workQueue.size() == config.getTextCheckerQueueSize())
log.warn("TextChecker queue is almost full requests in queue: {} active request: {}", queuesize, threadPoolExecutor.getActiveCount());
return true;
}
}
return false;
}

@NotNull
private Map<String, Integer> getRuleMatchCount(List<CheckResults> res) {
Map<String, Integer> ruleMatchCount = new HashMap<>();
Expand Down

0 comments on commit 5c777a4

Please sign in to comment.