Skip to content
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

Merged
merged 11 commits into from
May 14, 2024
Merged

Conversation

Almasgali
Copy link
Contributor

No description provided.

@@ -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"
Copy link

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).

Copy link
Contributor

@AlexeyShik AlexeyShik left a 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());
Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

write возвращает некоторый int - число байт, которые удалось записать.
Хотелось бы обработать также случай, когда не все данные успешно записаны. Ведь в таком случае клиент не сможет распарсить цельный ответ, так как он получит кусок чанка, который вполне может оборваться посреди байтов ключа или значения.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upd: что-то я не туда посмотрел, там ArrayQueueItem пишется, это будет гарантировать доставку всех данных, но если клиент медленный, то эти ArrayQueueItem будут копиться и выжрут всю оперативную память. Надо было написать чуть аккуратнее, чтобы данные вычитывались из итератора по мере записи в клиентский сокет.

@AlexeyShik AlexeyShik merged commit 854607b into polis-vk:main May 14, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants