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 Stage1 (polis-vk#13)
* base implementation of server * add test result files * add test result files * fix for code review comments --------- Co-authored-by: atimofeyev <[email protected]>
- Loading branch information
Showing
31 changed files
with
3,748 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/main/java/ru/vk/itmo/test/alenkovayulya/ServerImpl.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,109 @@ | ||
package ru.vk.itmo.test.alenkovayulya; | ||
|
||
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 java.io.IOException; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.function.Supplier; | ||
|
||
public class ServerImpl extends HttpServer { | ||
|
||
private final Dao<MemorySegment, Entry<MemorySegment>> referenceDao; | ||
|
||
public ServerImpl(ServiceConfig serviceConfig, | ||
Dao<MemorySegment, Entry<MemorySegment>> referenceDao) throws IOException { | ||
super(createServerConfig(serviceConfig)); | ||
this.referenceDao = referenceDao; | ||
} | ||
|
||
private static HttpServerConfig createServerConfig(ServiceConfig serviceConfig) { | ||
HttpServerConfig serverConfig = new HttpServerConfig(); | ||
AcceptorConfig acceptorConfig = new AcceptorConfig(); | ||
acceptorConfig.port = serviceConfig.selfPort(); | ||
acceptorConfig.reusePort = true; | ||
|
||
serverConfig.acceptors = new AcceptorConfig[]{acceptorConfig}; | ||
serverConfig.closeSessions = true; | ||
return serverConfig; | ||
} | ||
|
||
@Path("/v0/entity") | ||
@RequestMethod(Request.METHOD_GET) | ||
public Response getEntity(@Param(value = "id", required = true) String id) { | ||
return handleException(() -> { | ||
if (isEmptyId(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
Entry<MemorySegment> value = referenceDao.get( | ||
convertBytesToMemorySegment(id.getBytes(StandardCharsets.UTF_8))); | ||
|
||
return value == null ? new Response(Response.NOT_FOUND, Response.EMPTY) | ||
: Response.ok(value.value().toArray(ValueLayout.JAVA_BYTE)); | ||
}); | ||
} | ||
|
||
@Path("/v0/entity") | ||
@RequestMethod(Request.METHOD_PUT) | ||
public Response putEntity(@Param(value = "id", required = true) String id, Request request) { | ||
return handleException(() -> { | ||
if (isEmptyId(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
referenceDao.upsert(new BaseEntry<>( | ||
convertBytesToMemorySegment(id.getBytes(StandardCharsets.UTF_8)), | ||
convertBytesToMemorySegment(request.getBody()))); | ||
return new Response(Response.CREATED, Response.EMPTY); | ||
}); | ||
} | ||
|
||
@Path("/v0/entity") | ||
@RequestMethod(Request.METHOD_DELETE) | ||
public Response deleteEntity(@Param(value = "id", required = true) String id) { | ||
return handleException(() -> { | ||
if (isEmptyId(id)) { | ||
return new Response(Response.BAD_REQUEST, Response.EMPTY); | ||
} | ||
referenceDao.upsert(new BaseEntry<>( | ||
convertBytesToMemorySegment(id.getBytes(StandardCharsets.UTF_8)), null)); | ||
return new Response(Response.ACCEPTED, Response.EMPTY); | ||
}); | ||
} | ||
|
||
@Override | ||
public void handleDefault(Request request, HttpSession session) throws IOException { | ||
switch (request.getMethodName()) { | ||
case "GET", "PUT", "DELETE" -> session.sendResponse(new Response(Response.BAD_REQUEST, Response.EMPTY)); | ||
default -> session.sendResponse(new Response(Response.METHOD_NOT_ALLOWED, Response.EMPTY)); | ||
} | ||
} | ||
|
||
private boolean isEmptyId(String id) { | ||
return id.isEmpty() && id.isBlank(); | ||
} | ||
|
||
private MemorySegment convertBytesToMemorySegment(byte[] byteArray) { | ||
return MemorySegment.ofArray(byteArray); | ||
} | ||
|
||
private Response handleException(Supplier<Response> runnable) { | ||
try { | ||
return runnable.get(); | ||
} catch (Exception exception) { | ||
return new Response(Response.INTERNAL_ERROR, Response.EMPTY); | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/ru/vk/itmo/test/alenkovayulya/ServerInitializer.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,28 @@ | ||
package ru.vk.itmo.test.alenkovayulya; | ||
|
||
import ru.vk.itmo.ServiceConfig; | ||
import ru.vk.itmo.dao.Config; | ||
import ru.vk.itmo.test.alenkovayulya.dao.ReferenceDao; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
|
||
public final class ServerInitializer { | ||
public static final int PORT = 8080; | ||
public static final String URL = "http://localhost"; | ||
|
||
private ServerInitializer() { | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
ServiceConfig config = new ServiceConfig(PORT, URL, List.of(URL), | ||
Files.createTempDirectory("reports") | ||
); | ||
|
||
ReferenceDao dao = new ReferenceDao(new Config(config.workingDir(), 1024 * 1024 * 1024)); | ||
ServerImpl server = new ServerImpl(config, dao); | ||
server.start(); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/ru/vk/itmo/test/alenkovayulya/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,48 @@ | ||
package ru.vk.itmo.test.alenkovayulya; | ||
|
||
import ru.vk.itmo.Service; | ||
import ru.vk.itmo.ServiceConfig; | ||
import ru.vk.itmo.dao.Config; | ||
import ru.vk.itmo.dao.Dao; | ||
import ru.vk.itmo.dao.Entry; | ||
import ru.vk.itmo.test.ServiceFactory; | ||
import ru.vk.itmo.test.alenkovayulya.dao.ReferenceDao; | ||
|
||
import java.io.IOException; | ||
import java.lang.foreign.MemorySegment; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class ServiceImpl implements Service { | ||
|
||
private Dao<MemorySegment, Entry<MemorySegment>> referenceDao; | ||
private ServerImpl server; | ||
private final ServiceConfig config; | ||
|
||
public ServiceImpl(ServiceConfig config) { | ||
this.config = config; | ||
|
||
} | ||
|
||
@Override | ||
public synchronized CompletableFuture<Void> start() throws IOException { | ||
referenceDao = new ReferenceDao(new Config(config.workingDir(), 1024 * 1024 * 1024)); | ||
server = new ServerImpl(config, referenceDao); | ||
server.start(); | ||
return CompletableFuture.completedFuture(null); | ||
} | ||
|
||
@Override | ||
public synchronized CompletableFuture<Void> stop() throws IOException { | ||
server.stop(); | ||
referenceDao.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
+683 KB
src/main/java/ru/vk/itmo/test/alenkovayulya/cringe_results/alloc-put.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+990 KB
src/main/java/ru/vk/itmo/test/alenkovayulya/cringe_results/cpu-put.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
201 changes: 201 additions & 0 deletions
201
src/main/java/ru/vk/itmo/test/alenkovayulya/cringe_results/wrk-get-search-break-point.txt
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,201 @@ | ||
MacBook-Pro-Ulia:wrk2-arm yulalenk$ ./wrk -c 1 -d 20 -t 1 -L -R 40000 -s /Users/yulalenk/sem2/2024-highload-dht/src/main/java/ru/vk/itmo/test/alenkovayulya/lua/get.lua http://localhost:8080 | ||
Running 20s test @ http://localhost:8080 | ||
1 threads and 1 connections | ||
Thread calibration: mean lat.: 5.849ms, rate sampling interval: 42ms | ||
Thread Stats Avg Stdev Max +/- Stdev | ||
Latency 1.40ms 1.34ms 7.14ms 86.52% | ||
Req/Sec 60.77k 1.35k 63.63k 64.14% | ||
Latency Distribution (HdrHistogram - Recorded Latency) | ||
50.000% 1.00ms | ||
75.000% 1.62ms | ||
90.000% 3.17ms | ||
99.000% 6.25ms | ||
99.900% 6.86ms | ||
99.990% 7.12ms | ||
99.999% 7.14ms | ||
100.000% 7.15ms | ||
|
||
Detailed Percentile spectrum: | ||
Value Percentile TotalCount 1/(1-Percentile) | ||
|
||
0.011 0.000000 1 1.00 | ||
0.297 0.100000 60163 1.11 | ||
0.502 0.200000 120152 1.25 | ||
0.674 0.300000 180176 1.43 | ||
0.841 0.400000 240080 1.67 | ||
0.998 0.500000 299976 2.00 | ||
1.073 0.550000 329900 2.22 | ||
1.144 0.600000 359965 2.50 | ||
1.240 0.650000 389851 2.86 | ||
1.383 0.700000 419817 3.33 | ||
1.622 0.750000 449806 4.00 | ||
1.774 0.775000 464789 4.44 | ||
1.935 0.800000 479767 5.00 | ||
2.167 0.825000 494789 5.71 | ||
2.381 0.850000 509767 6.67 | ||
2.715 0.875000 524742 8.00 | ||
2.891 0.887500 532233 8.89 | ||
3.167 0.900000 539721 10.00 | ||
3.467 0.912500 547286 11.43 | ||
3.809 0.925000 554716 13.33 | ||
4.107 0.937500 562293 16.00 | ||
4.255 0.943750 565960 17.78 | ||
4.651 0.950000 569712 20.00 | ||
5.063 0.956250 573459 22.86 | ||
5.335 0.962500 577241 26.67 | ||
5.539 0.968750 580987 32.00 | ||
5.635 0.971875 582822 35.56 | ||
5.735 0.975000 584709 40.00 | ||
5.831 0.978125 586549 45.71 | ||
5.931 0.981250 588501 53.33 | ||
6.003 0.984375 590303 64.00 | ||
6.063 0.985938 591247 71.11 | ||
6.135 0.987500 592195 80.00 | ||
6.199 0.989062 593137 91.43 | ||
6.287 0.990625 594046 106.67 | ||
6.411 0.992188 595017 128.00 | ||
6.491 0.992969 595466 142.22 | ||
6.563 0.993750 595921 160.00 | ||
6.607 0.994531 596417 182.86 | ||
6.643 0.995313 596889 213.33 | ||
6.683 0.996094 597375 256.00 | ||
6.695 0.996484 597590 284.44 | ||
6.707 0.996875 597816 320.00 | ||
6.723 0.997266 598064 365.71 | ||
6.739 0.997656 598264 426.67 | ||
6.759 0.998047 598512 512.00 | ||
6.775 0.998242 598648 568.89 | ||
6.787 0.998437 598747 640.00 | ||
6.803 0.998633 598862 731.43 | ||
6.835 0.998828 598970 853.33 | ||
6.871 0.999023 599099 1024.00 | ||
6.887 0.999121 599142 1137.78 | ||
6.907 0.999219 599201 1280.00 | ||
6.919 0.999316 599260 1462.86 | ||
6.931 0.999414 599328 1706.67 | ||
6.951 0.999512 599374 2048.00 | ||
6.971 0.999561 599406 2275.56 | ||
6.991 0.999609 599434 2560.00 | ||
7.003 0.999658 599463 2925.71 | ||
7.019 0.999707 599492 3413.33 | ||
7.043 0.999756 599523 4096.00 | ||
7.055 0.999780 599546 4551.11 | ||
7.059 0.999805 599554 5120.00 | ||
7.067 0.999829 599566 5851.43 | ||
7.087 0.999854 599580 6826.67 | ||
7.099 0.999878 599596 8192.00 | ||
7.107 0.999890 599602 9102.22 | ||
7.119 0.999902 599614 10240.00 | ||
7.123 0.999915 599616 11702.86 | ||
7.131 0.999927 599632 13653.33 | ||
7.131 0.999939 599632 16384.00 | ||
7.135 0.999945 599644 18204.44 | ||
7.135 0.999951 599644 20480.00 | ||
7.135 0.999957 599644 23405.71 | ||
7.139 0.999963 599658 27306.67 | ||
7.139 0.999969 599658 32768.00 | ||
7.139 0.999973 599658 36408.89 | ||
7.139 0.999976 599658 40960.00 | ||
7.139 0.999979 599658 46811.43 | ||
7.139 0.999982 599658 54613.33 | ||
7.139 0.999985 599658 65536.00 | ||
7.139 0.999986 599658 72817.78 | ||
7.143 0.999988 599665 81920.00 | ||
7.143 0.999989 599665 93622.86 | ||
7.143 0.999991 599665 109226.67 | ||
7.143 0.999992 599665 131072.00 | ||
7.143 0.999993 599665 145635.56 | ||
7.143 0.999994 599665 163840.00 | ||
7.143 0.999995 599665 187245.71 | ||
7.143 0.999995 599665 218453.33 | ||
7.143 0.999996 599665 262144.00 | ||
7.143 0.999997 599665 291271.11 | ||
7.143 0.999997 599665 327680.00 | ||
7.143 0.999997 599665 374491.43 | ||
7.143 0.999998 599665 436906.67 | ||
7.143 0.999998 599665 524288.00 | ||
7.143 0.999998 599665 582542.22 | ||
7.147 0.999998 599666 655360.00 | ||
7.147 1.000000 599666 inf | ||
#[Mean = 1.401, StdDeviation = 1.335] | ||
#[Max = 7.144, Total count = 599666] | ||
#[Buckets = 27, SubBuckets = 2048] | ||
---------------------------------------------------------- | ||
|
||
|
||
MacBook-Pro-Ulia:wrk2-arm yulalenk$ ./wrk -c 1 -d 20 -t 1 -L -R 45000 -s /Users/yulalenk/sem2/2024-highload-dht/src/main/java/ru/vk/itmo/test/alenkovayulya/lua/get.lua http://localhost:8080 | ||
Running 20s test @ http://localhost:8080 | ||
1 threads and 1 connections | ||
Thread calibration: mean lat.: 357.882ms, rate sampling interval: 1247ms | ||
Thread Stats Avg Stdev Max +/- Stdev | ||
Latency 990.48ms 187.14ms 1.31s 57.09% | ||
Req/Sec 60.98k 368.85 61.65k 62.50% | ||
Latency Distribution (HdrHistogram - Recorded Latency) | ||
50.000% 991.23ms | ||
75.000% 1.15s | ||
90.000% 1.25s | ||
99.000% 1.31s | ||
99.900% 1.31s | ||
99.990% 1.31s | ||
99.999% 1.31s | ||
100.000% 1.31s | ||
|
||
Detailed Percentile spectrum: | ||
Value Percentile TotalCount 1/(1-Percentile) | ||
|
||
684.543 0.000000 410 1.00 | ||
737.279 0.100000 61204 1.11 | ||
788.991 0.200000 122597 1.25 | ||
854.527 0.300000 183121 1.43 | ||
923.135 0.400000 243738 1.67 | ||
991.231 0.500000 304612 2.00 | ||
1027.071 0.550000 335128 2.22 | ||
1057.791 0.600000 365948 2.50 | ||
1086.463 0.650000 396749 2.86 | ||
1119.231 0.700000 427638 3.33 | ||
1151.999 0.750000 457580 4.00 | ||
1167.359 0.775000 472406 4.44 | ||
1185.791 0.800000 487546 5.00 | ||
1204.223 0.825000 502839 5.71 | ||
1219.583 0.850000 518153 6.67 | ||
1236.991 0.875000 533445 8.00 | ||
1246.207 0.887500 541177 8.89 | ||
1253.375 0.900000 548955 10.00 | ||
1260.543 0.912500 556010 11.43 | ||
1268.735 0.925000 564372 13.33 | ||
1275.903 0.937500 571724 16.00 | ||
1281.023 0.943750 575675 17.78 | ||
1283.071 0.950000 578958 20.00 | ||
1287.167 0.956250 583208 22.86 | ||
1290.239 0.962500 587127 26.67 | ||
1293.311 0.968750 590206 32.00 | ||
1295.359 0.971875 592610 35.56 | ||
1298.431 0.975000 594029 40.00 | ||
1300.479 0.978125 595960 45.71 | ||
1303.551 0.981250 599479 53.33 | ||
1304.575 0.984375 600406 64.00 | ||
1305.599 0.985938 601403 71.11 | ||
1306.623 0.987500 602725 80.00 | ||
1306.623 0.989062 602725 91.43 | ||
1307.647 0.990625 603765 106.67 | ||
1308.671 0.992188 604645 128.00 | ||
1309.695 0.992969 605792 142.22 | ||
1309.695 0.993750 605792 160.00 | ||
1310.719 0.994531 607195 182.86 | ||
1310.719 0.995313 607195 213.33 | ||
1310.719 0.996094 607195 256.00 | ||
1310.719 0.996484 607195 284.44 | ||
1311.743 0.996875 608377 320.00 | ||
1311.743 0.997266 608377 365.71 | ||
1311.743 0.997656 608377 426.67 | ||
1311.743 0.998047 608377 512.00 | ||
1311.743 0.998242 608377 568.89 | ||
1311.743 0.998437 608377 640.00 | ||
1311.743 0.998633 608377 731.43 | ||
1312.767 0.998828 609179 853.33 | ||
1312.767 1.000000 609179 inf | ||
#[Mean = 990.484, StdDeviation = 187.145] | ||
#[Max = 1311.744, Total count = 609179] | ||
#[Buckets = 27, SubBuckets = 2048] | ||
---------------------------------------------------------- | ||
|
Oops, something went wrong.