Skip to content

Commit

Permalink
support OS env BUFSIZE and java -DBUFSIZE to set FastWriter.BUFSIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
mkhludnev committed Feb 25, 2023
1 parent c9fa21d commit f0ed425
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion solr/solrj/src/java/org/apache/solr/common/util/FastWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,38 @@

import java.io.IOException;
import java.io.Writer;
import java.lang.invoke.MethodHandles;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/** Single threaded BufferedWriter
* Internal Solr use only, subject to change.
*/
public class FastWriter extends Writer {
private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
// use default BUFSIZE of BufferedWriter so if we wrap that
// it won't cause double buffering.
private static final int BUFSIZE = 8192;
private static final int BUFSIZE;
static {
int bufSize=8192;
final String BUF_SIZE = "BUFSIZE";
try {
String env = System.getenv(BUF_SIZE);
bufSize = Integer.parseInt(env);
} catch (Exception e) {
log.debug("checking OS env for "+ BUF_SIZE,e);
try {
String prop = System.getProperty(BUF_SIZE, "8192");
bufSize = Integer.parseInt(prop);
} catch (Exception ee) {
log.debug("checking -D property for "+ BUF_SIZE,ee);
}
} finally {
log.info(FastWriter.class.getSimpleName()+"."+ BUF_SIZE + "=" + bufSize);
BUFSIZE = bufSize;
}
}
protected final Writer sink;
protected char[] buf;
protected int pos;
Expand Down

0 comments on commit f0ed425

Please sign in to comment.