Skip to content

Commit c19fb9e

Browse files
committed
Small change in UDP client
Change-Id: I375eaf56e55ee87cca38fbd56e087a833b059719
1 parent 08745b1 commit c19fb9e

File tree

3 files changed

+57
-67
lines changed

3 files changed

+57
-67
lines changed

src/main/com/schooner/MemCached/command/DeletionCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ public DeletionCommand(String key, Integer hashCode, Date expiry) {
6565
public boolean response(SchoonerSockIO sock, short rid) throws IOException {
6666
byte[] res = sock.getResponse(rid);
6767
if (Arrays.equals(res, DELETED)) {
68-
if (log.isInfoEnabled())
69-
log.info("DELETED!");
68+
if (log.isDebugEnabled())
69+
log.debug("DELETED!");
7070
return true;
7171
} else if (Arrays.equals(res, NOTFOUND)) {
72-
if (log.isInfoEnabled())
73-
log.info("NOT_FOUND!");
72+
// if (log.isDebugEnabled())
73+
log.debug("NOT_FOUND!");
7474
} else {
7575
log.error("error");
7676
}

src/main/com/schooner/MemCached/command/RetrievalCommand.java

Lines changed: 48 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import java.io.ByteArrayInputStream;
3232
import java.io.IOException;
3333
import java.util.Arrays;
34-
import java.util.LinkedList;
3534

3635
import org.slf4j.Logger;
3736
import org.slf4j.LoggerFactory;
@@ -88,7 +87,6 @@ public class Value {
8887
}
8988

9089
public class ResponseParser {
91-
private LinkedList<Value> list;
9290
public Value retvalue = null;
9391

9492
public void exec(byte[] res) throws IOException {
@@ -97,7 +95,6 @@ public void exec(byte[] res) throws IOException {
9795
byte[] end = new byte[5];
9896
byte next;
9997
int length = 0;
100-
int i = 0;
10198

10299
// check if it is the end.
103100
stream.mark(0);
@@ -107,80 +104,70 @@ public void exec(byte[] res) throws IOException {
107104
}
108105
stream.reset();
109106

110-
while (true) {
111-
Value value = new Value();
112-
// skip "VALUE <key> "
113-
stream.skip(B_VALUE.length + key.length() + 1);
107+
Value value = new Value();
108+
// skip "VALUE <key> "
109+
stream.skip(B_VALUE.length + key.length() + 1);
114110

115-
// get the length of <flags> and build it.
116-
length = 0;
117-
while ((next = (byte) stream.read()) != AscIIUDPClient.B_DELIMITER) {
118-
length++;
119-
sb.append((char) next);
120-
}
121-
try {
122-
value.flags = Integer.valueOf(sb.toString());
123-
} catch (NumberFormatException e) {
124-
retvalue = null;
125-
return;
126-
}
127-
sb.delete(0, length);
111+
// get the length of <flags> and build it.
112+
length = 0;
113+
while ((next = (byte) stream.read()) != AscIIUDPClient.B_DELIMITER) {
114+
length++;
115+
sb.append((char) next);
116+
}
117+
try {
118+
value.flags = Integer.valueOf(sb.toString());
119+
} catch (NumberFormatException e) {
120+
retvalue = null;
121+
return;
122+
}
123+
sb.delete(0, length);
124+
125+
// get the length of <byte> and build it.
126+
length = 0;
127+
while (((next = (byte) stream.read()) != AscIIUDPClient.B_DELIMITER) && (next != B_RETURN)) {
128+
length++;
129+
sb.append((char) next);
130+
}
128131

129-
// get the length of <byte> and build it.
132+
try {
133+
value.bytes = Integer.valueOf(sb.toString());
134+
} catch (NumberFormatException e) {
135+
retvalue = null;
136+
return;
137+
}
138+
sb.delete(0, length);
139+
140+
if (cmd.equals("gets")) {
141+
// if gets then get the length of <casUnique> and build it.
130142
length = 0;
131-
while (((next = (byte) stream.read()) != AscIIUDPClient.B_DELIMITER) && (next != B_RETURN)) {
143+
while ((next = (byte) stream.read()) != B_RETURN) {
132144
length++;
133145
sb.append((char) next);
134146
}
135-
136147
try {
137-
value.bytes = Integer.valueOf(sb.toString());
148+
value.casUnique = Long.valueOf(sb.toString());
138149
} catch (NumberFormatException e) {
139150
retvalue = null;
140151
return;
141152
}
142153
sb.delete(0, length);
154+
}
143155

144-
if (cmd.equals("gets")) {
145-
// if gets then get the length of <casUnique> and build it.
146-
length = 0;
147-
while ((next = (byte) stream.read()) != B_RETURN) {
148-
length++;
149-
sb.append((char) next);
150-
}
151-
try {
152-
value.casUnique = Long.valueOf(sb.toString());
153-
} catch (NumberFormatException e) {
154-
retvalue = null;
155-
return;
156-
}
157-
sb.delete(0, length);
158-
}
159-
160-
// skip "\n"
161-
stream.skip(1);
156+
// skip "\n"
157+
stream.skip(1);
162158

163-
// build datablock
164-
value.dataBlock = new byte[value.bytes];
165-
stream.read(value.dataBlock);
159+
// build datablock
160+
value.dataBlock = new byte[value.bytes];
161+
stream.read(value.dataBlock);
166162

167-
// skip "\r\n"
168-
stream.skip(2);
163+
// skip "\r\n"
164+
stream.skip(2);
169165

170-
// check if it is the end.
171-
stream.mark(0);
172-
stream.read(end);
173-
if (Arrays.equals(end, B_END)) {
174-
retvalue = value;
175-
break;
176-
} else {
177-
stream.reset();
178-
}
179-
if (i == 0) {
180-
list = new LinkedList<Value>();
181-
}
182-
list.add(value);
183-
i++;
166+
// check if it is the end.
167+
stream.mark(0);
168+
stream.read(end);
169+
if (Arrays.equals(end, B_END)) {
170+
retvalue = value;
184171
}
185172
}
186173
}

src/test/com/schooner/MemCached/MemCachedBenchUdp.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ public static void main(String[] args) {
5656
MemCachedClient mc = new MemCachedClient("test", false, false);
5757

5858
String keyBase = "testKey";
59-
String object = "This is a test of an object blah blah es, serialization does not seem to slow things down so much. The gzip compression is horrible horrible performance, so we only use it for very large objects. I have not done any heavy benchmarking recently";
59+
int[] object = new int[16 * 1020]; // 64K limit for UDP
60+
for (int i = 0; i < 16 * 1020; i++) {
61+
object[i] = i;
62+
}
6063

6164
long begin = System.currentTimeMillis();
6265
for (int i = start; i < start + runs; i++) {
@@ -68,7 +71,7 @@ public static void main(String[] args) {
6871

6972
begin = System.currentTimeMillis();
7073
for (int i = start; i < start + runs; i++) {
71-
mc.get(keyBase + i);
74+
System.out.println(mc.get(keyBase + i));
7275
}
7376
end = System.currentTimeMillis();
7477
time = end - begin;

0 commit comments

Comments
 (0)