forked from polis-vk/2024-highload-dht
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Волков Никита, ИТМО DWS, Stage 1 (polis-vk#17)
* init commit * data research result * result * refactoring --------- Co-authored-by: atimofeyev <[email protected]>
- Loading branch information
Showing
14 changed files
with
3,079 additions
and
0 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
src/main/java/ru/vk/itmo/test/volkovnikita/HttpServerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package ru.vk.itmo.test.volkovnikita; | ||
|
||
import one.nio.http.HttpServer; | ||
import one.nio.http.HttpServerConfig; | ||
import one.nio.http.HttpSession; | ||
import one.nio.http.Param; | ||
import one.nio.http.Path; | ||
import one.nio.http.Request; | ||
import one.nio.http.RequestMethod; | ||
import one.nio.http.Response; | ||
import one.nio.server.AcceptorConfig; | ||
import ru.vk.itmo.ServiceConfig; | ||
import ru.vk.itmo.dao.BaseEntry; | ||
import ru.vk.itmo.dao.Dao; | ||
import ru.vk.itmo.dao.Entry; | ||
import ru.vk.itmo.test.reference.dao.ReferenceDao; | ||
|
||
import java.io.IOException; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.util.Set; | ||
|
||
public class HttpServerImpl extends HttpServer { | ||
|
||
private final Dao<MemorySegment, Entry<MemorySegment>> dao; | ||
|
||
static final Set<String> METHODS = Set.of( | ||
"GET", | ||
"PUT", | ||
"DELETE" | ||
); | ||
|
||
public HttpServerImpl(ServiceConfig config, ReferenceDao dao) throws IOException { | ||
super(createServerConfig(config)); | ||
this.dao = dao; | ||
} | ||
|
||
private static HttpServerConfig createServerConfig(ServiceConfig config) { | ||
HttpServerConfig serverConfig = new HttpServerConfig(); | ||
AcceptorConfig acceptorConfig = new AcceptorConfig(); | ||
acceptorConfig.port = config.selfPort(); | ||
acceptorConfig.reusePort = true; | ||
|
||
serverConfig.acceptors = new AcceptorConfig[]{acceptorConfig}; | ||
serverConfig.closeSessions = true; | ||
return serverConfig; | ||
} | ||
|
||
@Path(value = "/v0/status") | ||
public Response status() { | ||
return Response.ok("It's okay (c) Tinkoff"); | ||
} | ||
|
||
@Path(value = "/v0/entity") | ||
@RequestMethod(Request.METHOD_GET) | ||
public Response getEntry(@Param(value = "id", required = true) String id) { | ||
if (isIdUncorrect(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
MemorySegment key = MemorySegment.ofArray(id.toCharArray()); | ||
Entry<MemorySegment> entry = dao.get(key); | ||
return entry == null ? new Response(Response.NOT_FOUND, Response.EMPTY) : | ||
new Response(Response.OK, entry.value().toArray(ValueLayout.JAVA_BYTE)); | ||
} | ||
|
||
@Path(value = "/v0/entity") | ||
@RequestMethod(Request.METHOD_PUT) | ||
public Response up(@Param(value = "id", required = true) String id, Request request) { | ||
if (isIdUncorrect(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
MemorySegment key = MemorySegment.ofArray(id.toCharArray()); | ||
MemorySegment value = MemorySegment.ofArray(request.getBody()); | ||
dao.upsert(new BaseEntry<>(key, value)); | ||
return new Response(Response.CREATED, Response.EMPTY); | ||
} | ||
|
||
@Path(value = "/v0/entity") | ||
@RequestMethod(Request.METHOD_DELETE) | ||
public Response deleteEntry(@Param(value = "id", required = true) String id) { | ||
if (isIdUncorrect(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
MemorySegment key = MemorySegment.ofArray(id.toCharArray()); | ||
dao.upsert(new BaseEntry<>(key, null)); | ||
return new Response(Response.ACCEPTED, Response.EMPTY); | ||
} | ||
|
||
@Override | ||
public void handleDefault(Request request, HttpSession session) throws IOException { | ||
Response response; | ||
if (METHODS.contains(request.getMethodName())) { | ||
response = new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
session.sendResponse(response); | ||
} else { | ||
response = new Response(Response.METHOD_NOT_ALLOWED, Response.EMPTY); | ||
session.sendResponse(response); | ||
} | ||
session.sendResponse(response); | ||
} | ||
|
||
private boolean isIdUncorrect(String id) { | ||
return id == null || id.isEmpty() || id.isBlank(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ru.vk.itmo.test.volkovnikita; | ||
|
||
import ru.vk.itmo.ServiceConfig; | ||
import ru.vk.itmo.dao.Config; | ||
import ru.vk.itmo.test.reference.dao.ReferenceDao; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
|
||
public final class Server { | ||
|
||
public static final long FLUSH_THRESHOLD_BYTES = 4 * 1024L; | ||
|
||
private Server() { | ||
|
||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
ServiceConfig config = new ServiceConfig( | ||
8080, | ||
"http://localhost", | ||
List.of("http://localhost"), | ||
Files.createTempDirectory(".") | ||
); | ||
ReferenceDao dao = new ReferenceDao(new Config(config.workingDir(), FLUSH_THRESHOLD_BYTES)); | ||
HttpServerImpl server = new HttpServerImpl(config, dao); | ||
server.start(); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/ru/vk/itmo/test/volkovnikita/ServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package ru.vk.itmo.test.volkovnikita; | ||
|
||
import ru.vk.itmo.Service; | ||
import ru.vk.itmo.ServiceConfig; | ||
import ru.vk.itmo.dao.Config; | ||
import ru.vk.itmo.test.ServiceFactory; | ||
import ru.vk.itmo.test.reference.dao.ReferenceDao; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ServiceImpl implements Service { | ||
public static final long FLUSH_THRESHOLD_BYTES = 4 * 1024L; | ||
|
||
private HttpServerImpl server; | ||
private final ServiceConfig config; | ||
private ReferenceDao dao; | ||
|
||
public ServiceImpl(ServiceConfig config) { | ||
this.config = config; | ||
} | ||
|
||
@Override | ||
public synchronized CompletableFuture<Void> start() throws IOException { | ||
dao = new ReferenceDao(new Config(config.workingDir(), FLUSH_THRESHOLD_BYTES)); | ||
server = new HttpServerImpl(config, dao); | ||
server.start(); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
@Override | ||
public synchronized CompletableFuture<Void> stop() throws IOException { | ||
server.stop(); | ||
dao.close(); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
@ServiceFactory(stage = 1) | ||
public static class Factory implements ServiceFactory.Factory { | ||
|
||
@Override | ||
public Service create(ServiceConfig config) { | ||
return new ServiceImpl(config); | ||
} | ||
} | ||
} |
Binary file added
BIN
+108 KB
src/main/java/ru/vk/itmo/test/volkovnikita/data/stage1/get/Histogram_get_2000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions
81
src/main/java/ru/vk/itmo/test/volkovnikita/data/stage1/get/get_result_2000
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
Value Percentile TotalCount 1/(1-Percentile) | ||
|
||
0.289 0.000000 1 1.00 | ||
0.608 0.100000 4007 1.11 | ||
0.827 0.200000 8017 1.25 | ||
1.020 0.300000 12022 1.43 | ||
1.216 0.400000 16038 1.67 | ||
1.401 0.500000 20050 2.00 | ||
1.515 0.550000 22028 2.22 | ||
1.709 0.600000 24031 2.50 | ||
2.026 0.650000 26035 2.86 | ||
2.627 0.700000 28035 3.33 | ||
3.503 0.750000 30038 4.00 | ||
4.019 0.775000 31043 4.44 | ||
4.555 0.800000 32049 5.00 | ||
5.139 0.825000 33042 5.71 | ||
5.931 0.850000 34046 6.67 | ||
6.775 0.875000 35046 8.00 | ||
7.187 0.887500 35548 8.89 | ||
7.655 0.900000 36045 10.00 | ||
8.147 0.912500 36552 11.43 | ||
8.767 0.925000 37050 13.33 | ||
9.647 0.937500 37550 16.00 | ||
10.087 0.943750 37800 17.78 | ||
10.695 0.950000 38052 20.00 | ||
11.367 0.956250 38299 22.86 | ||
12.367 0.962500 38550 26.67 | ||
13.207 0.968750 38799 32.00 | ||
13.767 0.971875 38925 35.56 | ||
14.263 0.975000 39051 40.00 | ||
15.031 0.978125 39174 45.71 | ||
15.999 0.981250 39300 53.33 | ||
17.263 0.984375 39428 64.00 | ||
17.647 0.985938 39490 71.11 | ||
18.303 0.987500 39551 80.00 | ||
19.311 0.989062 39612 91.43 | ||
20.591 0.990625 39675 106.67 | ||
22.159 0.992188 39739 128.00 | ||
22.895 0.992969 39769 142.22 | ||
23.839 0.993750 39800 160.00 | ||
25.023 0.994531 39831 182.86 | ||
26.191 0.995313 39864 213.33 | ||
27.615 0.996094 39894 256.00 | ||
28.399 0.996484 39910 284.44 | ||
28.767 0.996875 39927 320.00 | ||
28.927 0.997266 39942 365.71 | ||
29.167 0.997656 39957 426.67 | ||
29.599 0.998047 39972 512.00 | ||
30.191 0.998242 39980 568.89 | ||
30.415 0.998437 39988 640.00 | ||
30.735 0.998633 39996 731.43 | ||
31.711 0.998828 40004 853.33 | ||
32.495 0.999023 40011 1024.00 | ||
32.991 0.999121 40015 1137.78 | ||
33.471 0.999219 40019 1280.00 | ||
33.631 0.999316 40023 1462.86 | ||
33.695 0.999414 40027 1706.67 | ||
33.727 0.999512 40033 2048.00 | ||
33.727 0.999561 40033 2275.56 | ||
33.759 0.999609 40035 2560.00 | ||
33.791 0.999658 40037 2925.71 | ||
33.823 0.999707 40040 3413.33 | ||
33.855 0.999756 40043 4096.00 | ||
33.855 0.999780 40043 4551.11 | ||
33.855 0.999805 40043 5120.00 | ||
33.887 0.999829 40045 5851.43 | ||
33.887 0.999854 40045 6826.67 | ||
33.919 0.999878 40046 8192.00 | ||
33.919 0.999890 40046 9102.22 | ||
33.951 0.999902 40048 10240.00 | ||
33.951 0.999915 40048 11702.86 | ||
33.951 0.999927 40048 13653.33 | ||
33.951 0.999939 40048 16384.00 | ||
33.951 0.999945 40048 18204.44 | ||
34.015 0.999951 40049 20480.00 | ||
34.015 0.999957 40049 23405.71 | ||
34.015 0.999963 40049 27306.67 | ||
34.015 0.999969 40049 32768.00 | ||
34.015 0.999973 40049 36408.89 | ||
34.079 0.999976 40050 40960.00 | ||
34.079 1.000000 40050 inf |
Oops, something went wrong.