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

Осипов Даниил ИТМО ФИТИП HW5 #188

Merged
merged 32 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6f77b25
Update README.md
incubos Feb 11, 2024
4ae5574
Merge branch 'main' into incubos-fix-course-link
incubos Feb 11, 2024
15f9c9d
Merge branch 'main' into incubos-fix-course-link
incubos Feb 11, 2024
66c9e0c
hw1 without profiling
Sbread Feb 21, 2024
539bcb6
code climate
Sbread Feb 21, 2024
5190066
delete preview STR feature
Sbread Feb 21, 2024
6b5101e
code climate
Sbread Feb 21, 2024
be7a6ec
wrk test
Sbread Feb 21, 2024
0217638
report
Sbread Feb 29, 2024
acf2045
Merge remote-tracking branch 'upstream/incubos-fix-course-link' into hw2
Sbread Mar 6, 2024
1d8d726
Merge remote-tracking branch 'upstream/main' into hw2
Sbread Mar 6, 2024
0031542
hw2 code
Sbread Mar 6, 2024
15fc311
codeclimate
Sbread Mar 6, 2024
1ee4dd7
codeclimate 2
Sbread Mar 6, 2024
7f8e7f8
report2
Sbread Mar 6, 2024
cd2b0c5
Merge remote-tracking branch 'upstream/main' into hw3
Sbread Mar 13, 2024
d51771f
code
Sbread Mar 14, 2024
0cd0e16
code climate
Sbread Mar 14, 2024
2bca715
code climate 2
Sbread Mar 14, 2024
4cd83a0
report3
Sbread Mar 20, 2024
a6bea13
Merge branch 'main' into hw3
Sbread Mar 26, 2024
eea3041
Merge branch 'main' into hw3
daniil-ushkov Apr 1, 2024
face0b1
Merge remote-tracking branch 'upstream/main' into hw5.2
Sbread Apr 11, 2024
b42dd11
hw5 code
Sbread Apr 11, 2024
c67d945
hw5 codeclimate1
Sbread Apr 11, 2024
a2aadf3
hw5 codeclimate 2
Sbread Apr 11, 2024
14d7b58
hw5 codeclimate 3
Sbread Apr 11, 2024
36669a4
report5
Sbread Apr 29, 2024
dba18b9
upd rep, part 1
Sbread May 15, 2024
40664f4
upd rep, part 1 v2
Sbread May 15, 2024
e3b930b
upd rep, part 2
Sbread May 15, 2024
a24cb55
Merge branch 'main' into hw5.2
Sbread May 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public MergeHandleResult(HttpSession session, int size, int ack) {
public boolean add(int index, HandleResult handleResult) {
Copy link

Choose a reason for hiding this comment

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

'METHOD_DEF' has more than 1 empty lines before.

handleResults[index] = handleResult;
int valid = validateResultStatus(handleResult.status()) ? countValid.getAndIncrement() : countValid.get();
Copy link
Contributor

Choose a reason for hiding this comment

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

Единственное, тебе нужен incrementAndGet иначе тебе будет нужно ack + 1 ответов и например, если у тебя ack = 2, from = 3, то придётся ждать пока доработает последний

if (valid >= ack) {
if (valid == ack) {
sendResult();
return true;
}
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/ru/vk/itmo/test/osipovdaniil/ServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import ru.vk.itmo.ServiceConfig;
import ru.vk.itmo.test.osipovdaniil.dao.ReferenceBaseEntry;
import ru.vk.itmo.test.osipovdaniil.dao.ReferenceDao;

import java.io.IOException;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
Expand All @@ -35,6 +36,7 @@

public class ServerImpl extends HttpServer {

public static final int EXECUTOR_SERVICE_TERMINATION_TIMEOUT = 60;
public static final String ENTITY_PATH = "/v0/entity";
public static final String START = "start=";
private static final String HEADER_REMOTE = "X-flag-remote-server-to-node";
Expand All @@ -43,6 +45,7 @@ public class ServerImpl extends HttpServer {
private static final String HEADER_TIMESTAMP_ONE_NIO_HEADER = HEADER_TIMESTAMP + ": ";
private static final Logger log = LoggerFactory.getLogger(ServerImpl.class);
private static final int THREADS = Runtime.getRuntime().availableProcessors();
private static final long REMOTE_HEADER_TIMEOUT = 500;
public static final String ID = "id=";
public static final String ACK = "ack=";
public static final String FROM = "from=";
Expand Down Expand Up @@ -284,7 +287,7 @@ private HandleResult invokeRemote(final String executorNode, final Request reque
: HttpRequest.BodyPublishers.ofByteArray(request.getBody())
)
.header(HEADER_REMOTE, "true")
.timeout(Duration.ofMillis(500))
.timeout(Duration.ofMillis(REMOTE_HEADER_TIMEOUT))
.build();
final HttpResponse<byte[]> httpResponse = httpClient.send(httpRequest, HttpResponse.BodyHandlers.ofByteArray());
final Optional<String> string = httpResponse.headers().firstValue(HEADER_TIMESTAMP);
Expand Down Expand Up @@ -346,15 +349,15 @@ private int[] getIndexes(final String id, final int count) {
int[] maxHashs = new int[count];

for (int i = 0; i < count; i++) {
String url = config.clusterUrls().get(i);
int hash = Hash.murmur3(url + id);
final String url = config.clusterUrls().get(i);
final int hash = Hash.murmur3(url + id);
result[i] = i;
maxHashs[i] = hash;
}

for (int i = count; i < config.clusterUrls().size(); i++) {
Copy link
Contributor

Choose a reason for hiding this comment

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

А почему не посчитать хеш от всех clusterUrls, отсортировать и взять первые count?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

А зачем, у нас будет count * log(count), а так count + count * (cluster.size() - count). Тут ситуативно + у нас дефолтное значение count как раз cluster.size(), то есть я считаю что у нас достаточно случаев когда эта реализация работает лучше

String url = config.clusterUrls().get(i);
int hash = Hash.murmur3(url + id);
final String url = config.clusterUrls().get(i);
final int hash = Hash.murmur3(url + id);
for (int j = 0; j < maxHashs.length; j++) {
int maxHash = maxHashs[j];
if (maxHash < hash) {
Expand All @@ -373,11 +376,12 @@ private interface ERunnable {

private void shutdownAndAwaitTermination(ExecutorService pool) {
try {
if (!pool.awaitTermination(60, TimeUnit.MILLISECONDS)) {
if (!pool.awaitTermination(EXECUTOR_SERVICE_TERMINATION_TIMEOUT, TimeUnit.MILLISECONDS)) {
pool.shutdownNow();
if (!pool.awaitTermination(60, TimeUnit.MILLISECONDS)) {
if (!pool.awaitTermination(EXECUTOR_SERVICE_TERMINATION_TIMEOUT, TimeUnit.MILLISECONDS)) {
log.info("Pool did not terminate");
}

}
} catch (InterruptedException ie) {
pool.shutdownNow();
Expand Down
Loading
Loading