Revert "Merge branch 'fix-4xx-caching' into expermential_buffer_size_knob"
This reverts commitdcd05dc6a1
, reversing changes made to80402f3c52
.
This commit is contained in:
parent
dcd05dc6a1
commit
e85b77569b
|
@ -13,9 +13,5 @@
|
||||||
"web_settings": { //delete this block to disable webui
|
"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_hostname": "127.0.0.1", // "127.0.0.1" is the default and binds to localhost only
|
||||||
"ui_port": 8080
|
"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
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -129,10 +129,6 @@ object Main {
|
||||||
dieWithError("Config Error: Invalid UI port number")
|
dieWithError("Config Error: Invalid UI port number")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (settings.experimental != null) {
|
|
||||||
if (settings.experimental.maxBufferSizeForCacheHit < 0)
|
|
||||||
dieWithError("Config Error: Max cache buffer multiple must be >= 0")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private const val CLIENT_KEY_LENGTH = 52
|
private const val CLIENT_KEY_LENGTH = 52
|
||||||
|
|
|
@ -63,7 +63,7 @@ fun getServer(cache: DiskLruCache, serverSettings: ServerSettings, clientSetting
|
||||||
.setMaxConnPerRoute(3000)
|
.setMaxConnPerRoute(3000)
|
||||||
.build())
|
.build())
|
||||||
|
|
||||||
val imageServer = ImageServer(cache, database, statistics, serverSettings, clientSettings, client)
|
val imageServer = ImageServer(cache, database, statistics, serverSettings, client)
|
||||||
|
|
||||||
return timeRequest()
|
return timeRequest()
|
||||||
.then(catchAllHideDetails())
|
.then(catchAllHideDetails())
|
||||||
|
|
|
@ -48,7 +48,6 @@ import mdnet.base.data.ImageDatum
|
||||||
import mdnet.base.data.Statistics
|
import mdnet.base.data.Statistics
|
||||||
import mdnet.base.data.Token
|
import mdnet.base.data.Token
|
||||||
import mdnet.base.info
|
import mdnet.base.info
|
||||||
import mdnet.base.settings.ClientSettings
|
|
||||||
import mdnet.base.settings.ServerSettings
|
import mdnet.base.settings.ServerSettings
|
||||||
import mdnet.base.trace
|
import mdnet.base.trace
|
||||||
import mdnet.base.warn
|
import mdnet.base.warn
|
||||||
|
@ -67,7 +66,6 @@ class ImageServer(
|
||||||
private val database: Database,
|
private val database: Database,
|
||||||
private val statistics: AtomicReference<Statistics>,
|
private val statistics: AtomicReference<Statistics>,
|
||||||
private val serverSettings: ServerSettings,
|
private val serverSettings: ServerSettings,
|
||||||
private val clientSettings: ClientSettings,
|
|
||||||
private val client: HttpHandler
|
private val client: HttpHandler
|
||||||
) {
|
) {
|
||||||
init {
|
init {
|
||||||
|
@ -76,9 +74,6 @@ class ImageServer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private val executor = Executors.newCachedThreadPool()
|
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 {
|
fun handler(dataSaver: Boolean, tokenized: Boolean = false): HttpHandler {
|
||||||
val sodium = LazySodiumJava(SodiumJava())
|
val sodium = LazySodiumJava(SodiumJava())
|
||||||
|
@ -208,16 +203,11 @@ class ImageServer(
|
||||||
}
|
}
|
||||||
|
|
||||||
LOGGER.info { "Request for $sanitizedUri hit cache" }
|
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(
|
respondWithImage(
|
||||||
CipherInputStream(bufferedStream, cipher),
|
CipherInputStream(BufferedInputStream(snapshot.getInputStream(0)), cipher),
|
||||||
snapshot.getLength(0).toString(), imageDatum.contentType, imageDatum.lastModified,
|
snapshot.getLength(0).toString(), imageDatum.contentType, imageDatum.lastModified,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,8 +35,7 @@ data class ClientSettings(
|
||||||
val threads: Int = 4,
|
val threads: Int = 4,
|
||||||
val gracefulShutdownWaitSeconds: Int = 60,
|
val gracefulShutdownWaitSeconds: Int = 60,
|
||||||
val webSettings: WebSettings? = null,
|
val webSettings: WebSettings? = null,
|
||||||
val devSettings: DevSettings? = null,
|
val devSettings: DevSettings? = null
|
||||||
val experimental: Experimental? = null
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
|
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
|
||||||
|
@ -49,8 +48,3 @@ data class WebSettings(
|
||||||
data class DevSettings(
|
data class DevSettings(
|
||||||
val isDev: Boolean = false
|
val isDev: Boolean = false
|
||||||
)
|
)
|
||||||
|
|
||||||
@JsonNaming(PropertyNamingStrategy.SnakeCaseStrategy::class)
|
|
||||||
data class Experimental(
|
|
||||||
val maxBufferSizeForCacheHit: Int = 0
|
|
||||||
)
|
|
||||||
|
|
Loading…
Reference in a new issue