Вот код API: < /p>
Код: Выделить всё
@RestController
@RequestMapping("/log")
public class LogController {
private static final Logger logger = org.slf4j.LoggerFactory.getLogger(LogController.class);
private static final int LOOP_COUNT = 100;
@GetMapping("/system-out")
public String logSystemOut() {
long startTime = System.currentTimeMillis();
for (int i = 0; i < LOOP_COUNT; i++) {
System.out.println("hello world");
}
long endTime = System.currentTimeMillis();
return "Logged messages in " + (endTime - startTime) + " ms";
}
@GetMapping("/system-err")
public String logSystemErr() {
long startTime = System.currentTimeMillis();
for (int i = 0; i < LOOP_COUNT; i++) {
System.err.println("hello world");
}
long endTime = System.currentTimeMillis();
return "Logged messages in " + (endTime - startTime) + " ms";
}
@GetMapping("/info")
public String logInfo() {
long startTime = System.currentTimeMillis();
for (int i = 0; i < LOOP_COUNT; i++) {
logger.info("hello world");
}
long endTime = System.currentTimeMillis();
return "Logged messages in " + (endTime - startTime) + " ms";
}
}
< /code>
my recoverback.xml Конфигурация ниже: < /p>
logs/happyTest.log
logs/happyTest.%d{yyyy-MM-dd}.log
30
%msg%n
0
8192
Обратите внимание, что каждый разные API просто изменяет путь запроса на тест. .net/nexwbrpn.png "/>
на основе моего понимания, производительность system.out и system.err должна быть одинаковой и в целом ниже, чем logger.info В связи с тем, что я настраиваю ch.qos.logback.classic.asyncappender < /code> in rouge.xml.
Да, это работало, как я ожидал. logger.info < /code> лучше. >
Вот System.err < /code> производительность. значительно медленнее.
Вот система .out Выработка. быстрее по сравнению с system.err .
После просмотра исходного кода System.java я заметил, что различные из System.out и System.err только дескриптор Encode и File. Оба они буфериальны, не так, как некоторые утверждают, что система.// java.lang.System
// ... other code
public final static PrintStream out = null;
public final static PrintStream err = null;
// ... other code
private static void initializeSystemClass() {
// ... other code
FileInputStream fdIn = new FileInputStream(FileDescriptor.in);
FileOutputStream fdOut = new FileOutputStream(FileDescriptor.out);
FileOutputStream fdErr = new FileOutputStream(FileDescriptor.err);
setIn0(new BufferedInputStream(fdIn));
setOut0(newPrintStream(fdOut, props.getProperty("sun.stdout.encoding")));
setErr0(newPrintStream(fdErr, props.getProperty("sun.stderr.encoding")));
// ... other code
}
// ... other code
private static PrintStream newPrintStream(FileOutputStream fos, String enc) {
if (enc != null) {
try {
return new PrintStream(new BufferedOutputStream(fos, 128), true, enc);
} catch (UnsupportedEncodingException uee) {}
}
return new PrintStream(new BufferedOutputStream(fos, 128), true);
}
< /code>
Итак, почему производительность system.err < /code> значительно ниже, чем System.out < /code>?
Спасибо за понимание !
Подробнее здесь: https://stackoverflow.com/questions/794 ... m-out-in-j