fastWrite优化
This commit is contained in:
@@ -273,12 +273,12 @@ public abstract class AsyncConnection implements Channel, AutoCloseable {
|
||||
throw new RedkaleException("fast-writer handler is null");
|
||||
}
|
||||
for (Consumer<ByteArray> c : consumers) {
|
||||
this.fastWriteQueue.add(c);
|
||||
this.fastWriteQueue.offer(c);
|
||||
}
|
||||
this.ioWriteThread.fastWrite(this);
|
||||
}
|
||||
|
||||
protected abstract void fastPrepare(Object selector);
|
||||
protected abstract void fastPrepareInIOThread(Object selector);
|
||||
// --------------------- fast-write-end ---------------------
|
||||
|
||||
protected void startRead(CompletionHandler<Integer, ByteBuffer> handler) {
|
||||
|
||||
@@ -142,7 +142,7 @@ public class AsyncIOThread extends WorkThread {
|
||||
}
|
||||
|
||||
public final void fastWrite(AsyncConnection conn) {
|
||||
fastQueue.add(Objects.requireNonNull(conn));
|
||||
fastQueue.offer(Objects.requireNonNull(conn));
|
||||
selector.wakeup();
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ public class AsyncIOThread extends WorkThread {
|
||||
try {
|
||||
AsyncConnection fastConn;
|
||||
while ((fastConn = fastQueue.poll()) != null) {
|
||||
fastConn.fastPrepare(selector);
|
||||
fastConn.fastPrepareInIOThread(selector);
|
||||
}
|
||||
|
||||
Consumer<Selector> register;
|
||||
|
||||
@@ -177,11 +177,11 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fastPrepare(Object selector) {
|
||||
if (this.writePending) {
|
||||
return;
|
||||
protected void fastPrepareInIOThread(Object selector) {
|
||||
ByteArray array = this.fastWriteArray;
|
||||
if (!this.writePending) {
|
||||
array.clear();
|
||||
}
|
||||
ByteArray array = this.fastWriteArray.clear();
|
||||
Consumer<ByteArray> func;
|
||||
while ((func = fastWriteQueue.poll()) != null) {
|
||||
func.accept(array);
|
||||
@@ -373,6 +373,9 @@ abstract class AsyncNioConnection extends AsyncConnection {
|
||||
this.writeByteTuple2Offset = 0;
|
||||
this.writeByteTuple2Length = 0;
|
||||
}
|
||||
if (this.fastWriteArray != null) {
|
||||
this.fastWriteArray.clear();
|
||||
}
|
||||
}
|
||||
int writeCount;
|
||||
if (writeByteBuffer != null) {
|
||||
|
||||
Reference in New Issue
Block a user