mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-08-14 23:51:41 +00:00
Add multi-threading.
This commit is contained in:
parent
d02c76fc66
commit
4f945ebeac
4 changed files with 24 additions and 35 deletions
|
@ -31,6 +31,7 @@ dependencies {
|
||||||
implementation 'io.activej:activej-http:4.1'
|
implementation 'io.activej:activej-http:4.1'
|
||||||
implementation 'io.activej:activej-boot:4.1'
|
implementation 'io.activej:activej-boot:4.1'
|
||||||
implementation 'io.activej:activej-specializer:4.1'
|
implementation 'io.activej:activej-specializer:4.1'
|
||||||
|
implementation 'io.activej:activej-launchers-http:4.1'
|
||||||
implementation 'net.java.dev.jna:jna-platform:5.8.0'
|
implementation 'net.java.dev.jna:jna-platform:5.8.0'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
# The port to Listen on.
|
# The port to Listen on.
|
||||||
PORT: 8080
|
PORT: 8080
|
||||||
|
|
||||||
|
# The number of workers to use for the server
|
||||||
|
HTTP_WORKERS: 128
|
||||||
|
|
||||||
# Proxy
|
# Proxy
|
||||||
PROXY_PART: https://pipedproxy-ams.kavin.rocks
|
PROXY_PART: https://pipedproxy-ams.kavin.rocks
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
package me.kavin.piped;
|
package me.kavin.piped;
|
||||||
|
|
||||||
|
import static io.activej.config.converter.ConfigConverters.ofInetSocketAddress;
|
||||||
import static io.activej.http.HttpHeaders.CACHE_CONTROL;
|
import static io.activej.http.HttpHeaders.CACHE_CONTROL;
|
||||||
import static io.activej.http.HttpHeaders.CONTENT_TYPE;
|
import static io.activej.http.HttpHeaders.CONTENT_TYPE;
|
||||||
import static io.activej.inject.module.Modules.combine;
|
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
@ -15,40 +16,25 @@ import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.rometools.rome.feed.synd.SyndFeed;
|
import com.rometools.rome.feed.synd.SyndFeed;
|
||||||
import com.rometools.rome.io.SyndFeedInput;
|
import com.rometools.rome.io.SyndFeedInput;
|
||||||
|
|
||||||
import io.activej.eventloop.Eventloop;
|
import io.activej.config.Config;
|
||||||
import io.activej.http.AsyncHttpServer;
|
|
||||||
import io.activej.http.AsyncServlet;
|
import io.activej.http.AsyncServlet;
|
||||||
import io.activej.http.HttpMethod;
|
import io.activej.http.HttpMethod;
|
||||||
import io.activej.http.HttpResponse;
|
import io.activej.http.HttpResponse;
|
||||||
import io.activej.http.RoutingServlet;
|
import io.activej.http.RoutingServlet;
|
||||||
import io.activej.inject.annotation.Eager;
|
|
||||||
import io.activej.inject.annotation.Provides;
|
import io.activej.inject.annotation.Provides;
|
||||||
|
import io.activej.inject.module.AbstractModule;
|
||||||
import io.activej.inject.module.Module;
|
import io.activej.inject.module.Module;
|
||||||
import io.activej.launcher.Launcher;
|
import io.activej.launchers.http.MultithreadedHttpServerLauncher;
|
||||||
import io.activej.service.ServiceGraphModule;
|
|
||||||
import io.activej.worker.WorkerPool;
|
|
||||||
import io.activej.worker.WorkerPoolModule;
|
|
||||||
import io.activej.worker.WorkerPools;
|
|
||||||
import me.kavin.piped.consts.Constants;
|
import me.kavin.piped.consts.Constants;
|
||||||
import me.kavin.piped.utils.CustomServletDecorator;
|
import me.kavin.piped.utils.CustomServletDecorator;
|
||||||
import me.kavin.piped.utils.ResponseHelper;
|
import me.kavin.piped.utils.ResponseHelper;
|
||||||
import me.kavin.piped.utils.SponsorBlockUtils;
|
import me.kavin.piped.utils.SponsorBlockUtils;
|
||||||
import me.kavin.piped.utils.resp.ErrorResponse;
|
import me.kavin.piped.utils.resp.ErrorResponse;
|
||||||
|
|
||||||
public class ServerLauncher extends Launcher {
|
public class ServerLauncher extends MultithreadedHttpServerLauncher {
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
Eventloop eventloop() {
|
AsyncServlet mainServlet() {
|
||||||
return Eventloop.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
WorkerPool workerPool(WorkerPools workerPools) {
|
|
||||||
return workerPools.createPool(128);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Provides
|
|
||||||
AsyncServlet servlet() {
|
|
||||||
|
|
||||||
RoutingServlet router = RoutingServlet.create().map(HttpMethod.GET, "/webhooks/pubsub", request -> {
|
RoutingServlet router = RoutingServlet.create().map(HttpMethod.GET, "/webhooks/pubsub", request -> {
|
||||||
return HttpResponse.ok200().withPlainText(request.getQueryParameter("hub.challenge"));
|
return HttpResponse.ok200().withPlainText(request.getQueryParameter("hub.challenge"));
|
||||||
|
@ -147,20 +133,17 @@ public class ServerLauncher extends Launcher {
|
||||||
return new CustomServletDecorator(router);
|
return new CustomServletDecorator(router);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Module getOverrideModule() {
|
||||||
|
return new AbstractModule() {
|
||||||
@Provides
|
@Provides
|
||||||
@Eager
|
Config config() {
|
||||||
AsyncHttpServer server(Eventloop eventloop, AsyncServlet servlet) {
|
return Config.create()
|
||||||
return AsyncHttpServer.create(eventloop, servlet).withListenPort(Constants.PORT);
|
.with("http.listenAddresses",
|
||||||
|
Config.ofValue(ofInetSocketAddress(), new InetSocketAddress(PORT)))
|
||||||
|
.with("workers", Constants.HTTP_WORKERS);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
@Override
|
|
||||||
protected Module getModule() {
|
|
||||||
return combine(ServiceGraphModule.create(), WorkerPoolModule.create());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void run() throws Exception {
|
|
||||||
awaitShutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private @NotNull HttpResponse getJsonResponse(byte[] body, String cache) {
|
private @NotNull HttpResponse getJsonResponse(byte[] body, String cache) {
|
||||||
|
|
|
@ -19,6 +19,7 @@ public class Constants {
|
||||||
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0";
|
public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0";
|
||||||
|
|
||||||
public static final int PORT;
|
public static final int PORT;
|
||||||
|
public static final String HTTP_WORKERS;
|
||||||
|
|
||||||
public static final String PROXY_PART;
|
public static final String PROXY_PART;
|
||||||
|
|
||||||
|
@ -42,7 +43,8 @@ public class Constants {
|
||||||
YOUTUBE_SERVICE = NewPipe.getService(0);
|
YOUTUBE_SERVICE = NewPipe.getService(0);
|
||||||
prop.load(new FileReader("config.properties"));
|
prop.load(new FileReader("config.properties"));
|
||||||
|
|
||||||
PORT = Integer.parseInt(prop.getProperty("PORT"));
|
PORT = Integer.parseInt(prop.getProperty("PORT", "8080"));
|
||||||
|
HTTP_WORKERS = prop.getProperty("HTTP_WORKERS", "128");
|
||||||
PROXY_PART = prop.getProperty("PROXY_PART");
|
PROXY_PART = prop.getProperty("PROXY_PART");
|
||||||
CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL");
|
CAPTCHA_BASE_URL = prop.getProperty("CAPTCHA_BASE_URL");
|
||||||
CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY");
|
CAPTCHA_API_KEY = prop.getProperty("CAPTCHA_API_KEY");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue