-
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
Осипов Даниил ИТМО ФИТИП HW5 #188
Changes from all commits
6f77b25
4ae5574
15f9c9d
66c9e0c
539bcb6
5190066
6b5101e
be7a6ec
0217638
acf2045
1d8d726
0031542
15fc311
1ee4dd7
7f8e7f8
cd2b0c5
d51771f
0cd0e16
2bca715
4cd83a0
a6bea13
eea3041
face0b1
b42dd11
c67d945
a2aadf3
14d7b58
36669a4
dba18b9
40664f4
e3b930b
a24cb55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ public MergeHandleResult(HttpSession session, int size, int ack) { | |
public boolean add(int index, HandleResult handleResult) { | ||
handleResults[index] = handleResult; | ||
int valid = validateResultStatus(handleResult.status()) ? countValid.getAndIncrement() : countValid.get(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Единственное, тебе нужен |
||
if (valid >= ack) { | ||
if (valid == ack) { | ||
sendResult(); | ||
return true; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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"; | ||
|
@@ -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="; | ||
|
@@ -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); | ||
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. А почему не посчитать хеш от всех There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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(); | ||
|
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.
'METHOD_DEF' has more than 1 empty lines before.