Compare commits

...

12 commits

Author SHA1 Message Date
AviKav 7852030f8f
Merge branch 'master' into expermential_buffer_size_knob 2020-08-04 22:09:18 -04:00
AviKav d9a98148b7 Revert "Merge branch 'fix-4xx-caching' into expermential_buffer_size_knob"
This reverts commit dcd05dc6a1, reversing
changes made to 3d4843debd.
2020-08-04 21:44:59 -04:00
Avi Kav 848e0ba170 Revert "Revert "Merge branch 'fix-4xx-caching' into expermential_buffer_size_knob""
This reverts commit e85b77569b
2020-08-05 01:41:30 +00:00
AviKav e85b77569b Revert "Merge branch 'fix-4xx-caching' into expermential_buffer_size_knob"
This reverts commit dcd05dc6a1, reversing
changes made to 80402f3c52.
2020-08-04 21:37:45 -04:00
AviKav dcd05dc6a1 Merge branch 'fix-4xx-caching' into expermential_buffer_size_knob 2020-07-14 04:05:02 -04:00
AviKav 80402f3c52
Rename mimetype check 2020-07-14 03:59:07 -04:00
AviKav 0caa1f00a6
Add info to bad mimetype log entry and change spelling 2020-07-14 03:56:16 -04:00
AviKav 3558b5ad50
Fixes caching HTML from 404s 2020-07-14 03:50:42 -04:00
AviKav 3d4843debd
Update settings.sample.json again 2020-07-09 01:27:55 -04:00
AviKav ac3fe5df73
Update settings.sample.json 2020-07-09 01:00:11 -04:00
AviKav b763dbb4fa
Update settings.sample.json 2020-07-09 00:57:55 -04:00
AviKav 69d45575af
Experimential support for increasing the file buffer 2020-07-09 00:34:08 -04:00
6 changed files with 109 additions and 84 deletions

View file

@ -1,79 +1,79 @@
plugins {
id "java"
id "org.jetbrains.kotlin.jvm" version "1.3.72"
id "application"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "com.diffplug.gradle.spotless" version "4.4.0"
id "dev.afanasev.sekret" version "0.0.3"
}
group = "com.mangadex"
version = "git describe --tags --dirty".execute().text.trim()
mainClassName = "mdnet.base.Main"
repositories {
mavenCentral()
jcenter()
}
configurations {
runtime.exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-core"
runtime.exclude group: "com.sun.mail", module: "javax.mail"
}
dependencies {
compileOnly group: "dev.afanasev", name: "sekret-annotation", version: "0.0.3"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation group: "commons-io", name: "commons-io", version: "2.7"
implementation group: "org.http4k", name: "http4k-core", version: "$http_4k_version"
implementation group: "org.http4k", name: "http4k-format-jackson", version: "$http_4k_version"
implementation group: "com.fasterxml.jackson.datatype", name: "jackson-datatype-jsr310", version: "2.11.1"
implementation group: "org.http4k", name: "http4k-client-apache", version: "$http_4k_version"
implementation group: "org.http4k", name: "http4k-server-netty", version: "$http_4k_version"
runtimeOnly group: "io.netty", name: "netty-tcnative-boringssl-static", version: "2.0.30.Final"
implementation group: "ch.qos.logback", name: "logback-classic", version: "1.3.0-alpha4"
implementation group: "org.jetbrains.exposed", name: "exposed-core", version: "$exposed_version"
implementation group: "org.jetbrains.exposed", name: "exposed-dao", version: "$exposed_version"
implementation group: "org.jetbrains.exposed", name: "exposed-jdbc", version: "$exposed_version"
implementation group: "org.xerial", name: "sqlite-jdbc", version: "3.30.1"
implementation "com.goterl.lazycode:lazysodium-java:4.3.0"
implementation "net.java.dev.jna:jna:5.5.0"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
spotless {
lineEndings 'UNIX'
java {
targetExclude("build/generated/**/*")
eclipse()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
ktlint()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.register("generateVersion", Copy) {
def templateContext = [version: version]
inputs.properties templateContext
from "src/template/java"
into "$buildDir/generated/java"
expand templateContext
}
sourceSets.main.java.srcDir generateVersion.outputs.files
plugins {
id "java"
id "org.jetbrains.kotlin.jvm" version "1.3.72"
id "application"
id "com.github.johnrengelman.shadow" version "5.2.0"
id "com.diffplug.gradle.spotless" version "4.4.0"
id "dev.afanasev.sekret" version "0.0.3"
}
group = "com.mangadex"
version = "git describe --tags --dirty".execute().text.trim()
mainClassName = "mdnet.base.Main"
repositories {
mavenCentral()
jcenter()
}
configurations {
runtime.exclude group: "org.jetbrains.kotlinx", module: "kotlinx-coroutines-core"
runtime.exclude group: "com.sun.mail", module: "javax.mail"
}
dependencies {
compileOnly group: "dev.afanasev", name: "sekret-annotation", version: "0.0.3"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation "org.jetbrains.kotlin:kotlin-reflect"
implementation group: "commons-io", name: "commons-io", version: "2.7"
implementation group: "org.http4k", name: "http4k-core", version: "$http_4k_version"
implementation group: "org.http4k", name: "http4k-format-jackson", version: "$http_4k_version"
implementation group: "com.fasterxml.jackson.datatype", name: "jackson-datatype-jsr310", version: "2.11.1"
implementation group: "org.http4k", name: "http4k-client-apache", version: "$http_4k_version"
implementation group: "org.http4k", name: "http4k-server-netty", version: "$http_4k_version"
runtimeOnly group: "io.netty", name: "netty-tcnative-boringssl-static", version: "2.0.30.Final"
implementation group: "ch.qos.logback", name: "logback-classic", version: "1.3.0-alpha4"
implementation group: "org.jetbrains.exposed", name: "exposed-core", version: "$exposed_version"
implementation group: "org.jetbrains.exposed", name: "exposed-dao", version: "$exposed_version"
implementation group: "org.jetbrains.exposed", name: "exposed-jdbc", version: "$exposed_version"
implementation group: "org.xerial", name: "sqlite-jdbc", version: "3.30.1"
implementation "com.goterl.lazycode:lazysodium-java:4.2.6"
implementation "net.java.dev.jna:jna:5.5.0"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
spotless {
lineEndings 'UNIX'
java {
targetExclude("build/generated/**/*")
eclipse()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
kotlin {
ktlint()
trimTrailingWhitespace()
endWithNewline()
}
}
tasks.register("generateVersion", Copy) {
def templateContext = [version: version]
inputs.properties templateContext
from "src/template/java"
into "$buildDir/generated/java"
expand templateContext
}
sourceSets.main.java.srcDir generateVersion.outputs.files

View file

@ -13,5 +13,9 @@
"web_settings": { //delete this block to disable webui
"ui_hostname": "127.0.0.1", // "127.0.0.1" is the default and binds to localhost only
"ui_port": 8080
},
"experimental": {
"max_buffer_size_for_cache_hit": 0 // Size is n * 8kiB. 0 uses the JDK default (which is likely 8kiB).
// May improve diskIO at the cost of memory pressure. Testing needed
}
}

View file

@ -476,6 +476,11 @@ class MangaDexClient(private val clientSettingsFile: String) {
throw ClientSettingsException("Config Error: Invalid UI port number")
}
}
if (settings.experimental != null) {
if (settings.experimental.maxBufferSizeForCacheHit < 0)
throw ClientSettingsException("Config Error: Max cache buffer multiple must be >= 0")
}
}
private fun readClientSettings(): ClientSettings {

View file

@ -63,7 +63,7 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
.setMaxConnPerRoute(3000)
.build())
val imageServer = ImageServer(cache, database, statistics, serverSettings, client)
val imageServer = ImageServer(cache, database, statistics, serverSettings, clientSettings, client)
return timeRequest()
.then(catchAllHideDetails())

View file

@ -48,6 +48,7 @@ import mdnet.base.data.ImageDatum
import mdnet.base.data.Statistics
import mdnet.base.data.Token
import mdnet.base.info
import mdnet.base.settings.ClientSettings
import mdnet.base.settings.ServerSettings
import mdnet.base.trace
import mdnet.base.warn
@ -66,6 +67,7 @@ class ImageServer(
private val database: Database,
private val statistics: AtomicReference<Statistics>,
private val serverSettings: ServerSettings,
private val clientSettings: ClientSettings,
private val client: HttpHandler
) {
init {
@ -74,6 +76,9 @@ class ImageServer(
}
}
private val executor = Executors.newCachedThreadPool()
private val maxBufferSizeForCacheHit: Int? = clientSettings.experimental?.maxBufferSizeForCacheHit
?.takeUnless { it == 0 }
?.times(8 * 1024)
fun handler(dataSaver: Boolean, tokenized: Boolean = false): HttpHandler {
return baseHandler().then { request ->
@ -191,11 +196,16 @@ class ImageServer(
}
LOGGER.info { "Request for $sanitizedUri hit cache" }
val cacheStream = snapshot.getInputStream(0)
val bufferSize = maxBufferSizeForCacheHit?.coerceAtMost(snapshot.getLength(0).toInt())
val bufferedStream = bufferSize?.let {
BufferedInputStream(cacheStream, bufferSize)
} ?: BufferedInputStream(cacheStream) // Todo: Move into builder. It's untidy having the null propagate all the way here but I'm tired and tomorrow is a fast day.
respondWithImage(
CipherInputStream(BufferedInputStream(snapshot.getInputStream(0)), cipher),
snapshot.getLength(0).toString(), imageDatum.contentType, imageDatum.lastModified,
true
CipherInputStream(bufferedStream, cipher),
snapshot.getLength(0).toString(), imageDatum.contentType, imageDatum.lastModified,
true
)
}
}

View file

@ -35,7 +35,8 @@ data class ClientSettings(
val threads: Int = 4,
val gracefulShutdownWaitSeconds: Int = 60,
val webSettings: WebSettings? = null,
val devSettings: DevSettings? = null
val devSettings: DevSettings? = null,
val experimental: Experimental? = null
)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
@ -48,3 +49,8 @@ data class WebSettings(
data class DevSettings(
val isDev: Boolean = false
)
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
data class Experimental(
val maxBufferSizeForCacheHit: Int = 0
)