Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
BigDataViewer_Server_Extension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BioinformaticDataCompression
BigDataViewer_Server_Extension
Commits
9712fcfb
Commit
9712fcfb
authored
4 years ago
by
Vojtech Moravec
Browse files
Options
Downloads
Patches
Plain Diff
Use cached memory buffers which can be reused.
parent
3802b06f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/bdv/server/CellHandler.java
+41
-7
41 additions, 7 deletions
src/main/java/bdv/server/CellHandler.java
with
41 additions
and
7 deletions
src/main/java/bdv/server/CellHandler.java
+
41
−
7
View file @
9712fcfb
...
...
@@ -46,6 +46,8 @@ import java.io.*;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.Stack
;
import
java.util.concurrent.locks.ReentrantLock
;
public
class
CellHandler
extends
ContextHandler
{
private
long
transferedDataSize
=
0
;
...
...
@@ -99,9 +101,10 @@ public class CellHandler extends ContextHandler {
* Compression stuff.
*/
private
final
CompressionOptions
compressionParams
;
private
ICacheFile
compressionCacheFile
=
null
;
private
ImageCompressor
compressor
=
null
;
private
MemoryOutputStream
cachedCompressionStream
=
null
;
private
Stack
<
MemoryOutputStream
>
cachedBuffers
=
null
;
private
ICacheFile
compressionCacheFile
=
null
;
private
final
int
INITIAL_BUFFER_SIZE
=
2048
;
public
CellHandler
(
final
String
baseUrl
,
final
String
xmlFilename
,
final
String
datasetName
,
final
String
thumbnailsDirectory
,
final
CompressionOptions
compressionParams
)
throws
SpimDataException
,
IOException
{
...
...
@@ -143,8 +146,27 @@ public class CellHandler extends ContextHandler {
LOG
.
info
(
"CellHandler loaded codebook cache file. '"
+
compressionCacheFile
+
"'"
);
System
.
out
.
println
(
"\u001b[33mCellHandler::initializeCompression() loaded codebook cache file for: "
+
baseFilename
+
"\u001b[0m"
);
final
int
initialCompressionCacheSize
=
10
;
compressor
=
new
ImageCompressor
(
compressionParams
,
compressionCacheFile
);
cachedCompressionStream
=
new
MemoryOutputStream
(
4096
);
cachedBuffers
=
new
Stack
<>();
for
(
int
i
=
0
;
i
<
initialCompressionCacheSize
;
i
++)
{
cachedBuffers
.
push
(
new
MemoryOutputStream
(
INITIAL_BUFFER_SIZE
));
}
}
private
synchronized
MemoryOutputStream
getCachedCompressionBuffer
()
{
if
(!
cachedBuffers
.
empty
())
{
return
cachedBuffers
.
pop
();
}
else
{
return
new
MemoryOutputStream
(
INITIAL_BUFFER_SIZE
);
}
}
private
synchronized
void
returnBufferForReuse
(
MemoryOutputStream
buffer
)
{
buffer
.
reset
();
cachedBuffers
.
push
(
buffer
);
}
private
short
[]
getCachedVolatileCellData
(
final
String
[]
parts
,
final
int
[]
cellDims
)
{
...
...
@@ -227,19 +249,31 @@ public class CellHandler extends ContextHandler {
final
short
[]
data
=
getCachedVolatileCellData
(
parts
,
cellDims
);
assert
(
compressor
!=
null
);
compressor
.
setInputData
(
createInputDataObject
(
data
,
cellDims
));
cachedCompressionStream
.
reset
();
final
int
compressedContentLength
=
compressor
.
streamCompressChunk
(
cachedCompressionStream
);
final
FlatBufferInputData
inputData
=
createInputDataObject
(
data
,
cellDims
);
MemoryOutputStream
cellCompressionStream
=
getCachedCompressionBuffer
();
final
int
compressedContentLength
=
compressor
.
streamCompressChunk
(
cellCompressionStream
,
inputData
);
response
.
setContentLength
(
compressedContentLength
);
try
(
OutputStream
responseStream
=
response
.
getOutputStream
())
{
responseStream
.
write
(
c
ached
CompressionStream
.
getBuffer
(),
0
,
c
ached
CompressionStream
.
getCurrentBufferLength
());
responseStream
.
write
(
c
ell
CompressionStream
.
getBuffer
(),
0
,
c
ell
CompressionStream
.
getCurrentBufferLength
());
}
assert
(
cellCompressionStream
.
getCurrentBufferLength
()
==
compressedContentLength
)
:
"compressor.streamCompressChunk() is not equal to cachedCompressionStream.getCurrentBufferLength()"
;
if
(
cellCompressionStream
.
getCurrentBufferLength
()
!=
compressedContentLength
)
{
System
.
err
.
printf
(
"stream size\t%d\nreported size\t%d\n\n"
,
cellCompressionStream
.
getCurrentBufferLength
(),
compressedContentLength
);
}
response
.
setContentType
(
"application/octet-stream"
);
response
.
setStatus
(
HttpServletResponse
.
SC_OK
);
baseRequest
.
setHandled
(
true
);
returnBufferForReuse
(
cellCompressionStream
);
}
else
if
(
parts
[
0
].
equals
(
"init"
))
{
respondWithString
(
baseRequest
,
response
,
"application/json"
,
metadataJson
);
}
else
if
(
parts
[
0
].
equals
(
"init_qcmp"
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment