-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Khadyrov Almasgali, ITMO CT, M33351, Stage6 #210
Conversation
@@ -42,22 +42,25 @@ public class DaoServer extends HttpServer { | |||
private static final String HEADER_REMOTE_ONE_NIO_HEADER = HEADER_REMOTE + ": da"; | |||
private static final String HEADER_TIMESTAMP = "X-flag-remote-reference-server-to-node-by-paschenko2"; | |||
private static final String HEADER_TIMESTAMP_ONE_NIO_HEADER = HEADER_TIMESTAMP + ": "; | |||
private static final byte[] CHUNK_HEADERS = | |||
"HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nTransfer-Encoding: chunked\r\nConnection: keep-alive\r\n\r\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is longer than 120 characters (found 121).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Есть замечание и предложение по оптимизации, 14 баллов.
} | ||
writeFull(session, CHUNK_HEADERS); | ||
while (iterator.hasNext()) { | ||
writeChunk(session, iterator.next()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Получается много записей в сокет (writeFull) с небольшими значениями (отдельно на ключ, значения, сепараторы).
Будет эффективнее строить один блок, возможно из нескольких пар ключ-значение, чтобы делать меньше операций записи в сокет.
} | ||
|
||
private void writeFull(HttpSession session, byte[] data) throws IOException { | ||
session.write(data, 0, data.length); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
write возвращает некоторый int - число байт, которые удалось записать.
Хотелось бы обработать также случай, когда не все данные успешно записаны. Ведь в таком случае клиент не сможет распарсить цельный ответ, так как он получит кусок чанка, который вполне может оборваться посреди байтов ключа или значения.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upd: что-то я не туда посмотрел, там ArrayQueueItem пишется, это будет гарантировать доставку всех данных, но если клиент медленный, то эти ArrayQueueItem будут копиться и выжрут всю оперативную память. Надо было написать чуть аккуратнее, чтобы данные вычитывались из итератора по мере записи в клиентский сокет.
No description provided.