Hi,
I was performance testing the SocketAppender and found it too slow and
CPU intensive.So I made some changes to LoggingEvent.
LoggingEvent is now Externalizable instead of Serializable. This should
be compatible with JDK 1.1 as well.
My performance measurements give me 30-50% more throughput.
BR
Ole Dalgaard
Index: src/java/org/apache/log4j/spi/LocationInfo.java
===================================================================
RCS file:
/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/spi/LocationInfo.java,v
retrieving revision 1.11
diff -w -r1.11 LocationInfo.java
139a140,143
> public LocationInfo(String fullInfo) {
> this.fullInfo = fullInfo;
> }
>
Index: src/java/org/apache/log4j/spi/LoggingEvent.java
===================================================================
RCS file:
/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/spi/LoggingEvent.java,v
retrieving revision 1.26
diff -w -r1.26 LoggingEvent.java
19a20,23
> import java.io.ObjectOutput;
> import java.io.ObjectInput;
> import java.io.IOException;
>
38c42
< public class LoggingEvent implements java.io.Serializable {
---
> public class LoggingEvent implements java.io.Externalizable {
53c57
< public final String categoryName;
---
> public String categoryName;
160a165,176
> /**
> *Used by Externalizable
> */
> public LoggingEvent() {
> this.fqnOfCategoryClass = "";
> this.logger = null;
> this.categoryName = "";
> this.level = null;
> this.message = "";
> this.timeStamp = 0L;
> }
>
293,295c309
<
< private
< void readLevel(ObjectInputStream ois)
---
> private void readLevel(ObjectInput oi)
298c312
< int p = ois.readInt();
---
> int p = oi.readInt();
300,301c314,315
< String className = (String) ois.readObject();
< if(className == null) {
---
> String className = (String) oi.readUTF();
> if (className.equals("")) {
319,327d332
< private void readObject(ObjectInputStream ois)
< throws java.io.IOException, ClassNotFoundException {
< ois.defaultReadObject();
< readLevel(ois);
<
< // Make sure that no location info is available to Layouts
< if(locationInfo == null)
< locationInfo = new LocationInfo(null, null);
< }
329,333c334
< private
< void writeObject(ObjectOutputStream oos) throws java.io.IOException {
< // Aside from returning the current thread name the wgetThreadName
< // method sets the threadName variable.
< this.getThreadName();
---
> private void writeLevel(ObjectOutput oo) throws java.io.IOException {
335,336c336
< // This sets the renders the message in case it wasn't up to now.
< this.getRenderedMessage();
---
> oo.writeInt(level.toInt());
338,340c338,346
< // This call has a side effect of setting this.ndc and
< // setting ndcLookupRequired to false if not already false.
< this.getNDC();
---
> Class clazz = level.getClass();
> if (clazz == Level.class) {
> oo.writeUTF("");
> } else {
> // writing directly the Class object would be nicer, except that
> // serialized a Class object can not be read back by JDK
> // 1.1.x. We have to resort to this hack instead.
> oo.writeUTF(clazz.getName());
> }
342,343c348
< // This sets the throwable sting representation of the event throwable.
< this.getThrowableStrRep();
---
> }
345d349
< oos.defaultWriteObject();
347,348c351,369
< // serialize this event's level
< writeLevel(oos);
---
> public void readExternal(java.io.ObjectInput s)
> throws ClassNotFoundException, IOException {
> categoryName = s.readUTF();
> renderedMessage = s.readUTF();
> ndc = s.readUTF();
> threadName = s.readUTF();
> readLevel(s);
> int nr = s.readInt();
> if (nr > 0) {
> String[] rep = new String[nr];
> for (int i = 0; i < nr; i++) {
> rep[i] = s.readUTF();
> }
> throwableInfo = new ThrowableInformation(rep);
> }
> String locInfo = s.readUTF();
> if(!locInfo.equals("")) {
> locationInfo = new LocationInfo(locInfo);
> }
351,352c372,376
< private
< void writeLevel(ObjectOutputStream oos) throws java.io.IOException {
---
> public void writeExternal(java.io.ObjectOutput s)
> throws IOException {
> this.getThreadName();
> this.getRenderedMessage();
> this.getNDC();
354c378,379
< oos.writeInt(level.toInt());
---
> s.writeUTF(categoryName);
> s.writeUTF(renderedMessage);
356,358c381,387
< Class clazz = level.getClass();
< if(clazz == Level.class) {
< oos.writeObject(null);
---
> s.writeUTF(ndc == null ? "" : ndc);
> s.writeUTF(threadName);
> writeLevel(s);
> String[] throwableStr = this.getThrowableStrRep();
>
> if (throwableStr == null) {
> s.writeInt(0);
360,363c389,397
< // writing directly the Class object would be nicer, except that
< // serialized a Class object can not be read back by JDK
< // 1.1.x. We have to resort to this hack instead.
< oos.writeObject(clazz.getName());
---
> s.writeInt(throwableStr.length);
> for (int i = 0; i < throwableStr.length; i++) {
> s.writeUTF(throwableStr[i]);
> }
> }
> if(locationInfo != null) {
> s.writeUTF(locationInfo.fullInfo);
> } else {
> s.writeUTF("");
Index: src/java/org/apache/log4j/spi/ThrowableInformation.java
===================================================================
RCS file:
/home/cvspublic/jakarta-log4j/src/java/org/apache/log4j/spi/ThrowableInformation.java,v
retrieving revision 1.6
diff -w -r1.6 ThrowableInformation.java
31a32,37
> ThrowableInformation(String[] rep) {
> this.rep = rep;
> this.throwable = null;
> }
>
> public
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>