Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
imghost-backend
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Janne Mareike Koschinski
imghost-backend
Commits
3ee6b58a
Verified
Commit
3ee6b58a
authored
3 years ago
by
Janne Mareike Koschinski
Browse files
Options
Downloads
Patches
Plain Diff
Measure processing time more precisely
Signed-off-by:
Janne Mareike Koschinski
<
janne@kuschku.de
>
parent
63a74637
No related branches found
No related tags found
No related merge requests found
Pipeline
#2718
passed
3 years ago
Stage: build
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
main.go
+8
-3
8 additions, 3 deletions
main.go
process.go
+5
-5
5 additions, 5 deletions
process.go
resize.go
+8
-0
8 additions, 0 deletions
resize.go
with
21 additions
and
8 deletions
main.go
+
8
−
3
View file @
3ee6b58a
...
@@ -30,10 +30,15 @@ var imageCounter = promauto.NewCounterVec(
...
@@ -30,10 +30,15 @@ var imageCounter = promauto.NewCounterVec(
var
imageCounterSuccess
=
imageCounter
.
WithLabelValues
(
"success"
)
var
imageCounterSuccess
=
imageCounter
.
WithLabelValues
(
"success"
)
var
imageCounterFailure
=
imageCounter
.
WithLabelValues
(
"failure"
)
var
imageCounterFailure
=
imageCounter
.
WithLabelValues
(
"failure"
)
var
imageProcessDuration
=
promauto
.
NewCounter
(
prometheus
.
CounterOpts
{
var
imageProcessDuration
=
promauto
.
NewCounter
Vec
(
prometheus
.
CounterOpts
{
Name
:
"imghost_process_duration"
,
Name
:
"imghost_process_duration"
,
Help
:
"The total amount of time spent processing images"
,
Help
:
"The amount of time spent processing images"
,
})
},
[]
string
{
"task"
})
var
imageProcessDurationRead
=
imageProcessDuration
.
WithLabelValues
(
"read"
)
var
imageProcessDurationClone
=
imageProcessDuration
.
WithLabelValues
(
"clone"
)
var
imageProcessDurationCrop
=
imageProcessDuration
.
WithLabelValues
(
"crop"
)
var
imageProcessDurationResize
=
imageProcessDuration
.
WithLabelValues
(
"resize"
)
var
imageProcessDurationWrite
=
imageProcessDuration
.
WithLabelValues
(
"write"
)
func
main
()
{
func
main
()
{
config
:=
NewConfigFromEnv
()
config
:=
NewConfigFromEnv
()
...
...
This diff is collapsed.
Click to expand it.
process.go
+
5
−
5
View file @
3ee6b58a
...
@@ -5,21 +5,21 @@ import (
...
@@ -5,21 +5,21 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8"
"github.com/prometheus/client_golang/prometheus"
"os"
"os"
"path/filepath"
"path/filepath"
"time"
"time"
)
)
func
trackTime
(
start
time
.
Time
,
function
func
(
time
.
Duration
))
{
func
trackTimeSince
(
counter
prometheus
.
Counter
,
start
time
.
Time
)
time
.
Time
{
function
(
time
.
Now
()
.
UTC
()
.
Sub
(
start
.
UTC
()))
now
:=
time
.
Now
()
.
UTC
()
counter
.
Add
(
float64
(
now
.
Sub
(
start
)
.
Milliseconds
())
/
1000.0
)
return
now
}
}
func
ProcessImage
(
ctx
context
.
Context
,
config
*
Config
,
client
*
redis
.
Client
,
value
string
)
{
func
ProcessImage
(
ctx
context
.
Context
,
config
*
Config
,
client
*
redis
.
Client
,
value
string
)
{
queueGaugeInProgress
.
Inc
()
queueGaugeInProgress
.
Inc
()
defer
queueGaugeInProgress
.
Dec
()
defer
queueGaugeInProgress
.
Dec
()
defer
trackTime
(
time
.
Now
(),
func
(
duration
time
.
Duration
)
{
imageProcessDuration
.
Add
(
float64
(
duration
.
Milliseconds
()))
})
image
:=
Image
{}
image
:=
Image
{}
if
err
:=
json
.
Unmarshal
([]
byte
(
value
),
&
image
);
err
!=
nil
{
if
err
:=
json
.
Unmarshal
([]
byte
(
value
),
&
image
);
err
!=
nil
{
...
...
This diff is collapsed.
Click to expand it.
resize.go
+
8
−
0
View file @
3ee6b58a
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"github.com/justjanne/imgconv"
"github.com/justjanne/imgconv"
"gopkg.in/gographics/imagick.v3/imagick"
"gopkg.in/gographics/imagick.v3/imagick"
"path/filepath"
"path/filepath"
"time"
)
)
func
ResizeImage
(
config
*
Config
,
imageId
string
)
[]
error
{
func
ResizeImage
(
config
*
Config
,
imageId
string
)
[]
error
{
...
@@ -13,6 +14,7 @@ func ResizeImage(config *Config, imageId string) []error {
...
@@ -13,6 +14,7 @@ func ResizeImage(config *Config, imageId string) []error {
wand
:=
imagick
.
NewMagickWand
()
wand
:=
imagick
.
NewMagickWand
()
defer
wand
.
Destroy
()
defer
wand
.
Destroy
()
startRead
:=
time
.
Now
()
.
UTC
()
if
err
=
wand
.
ReadImage
(
filepath
.
Join
(
config
.
SourceFolder
,
imageId
));
err
!=
nil
{
if
err
=
wand
.
ReadImage
(
filepath
.
Join
(
config
.
SourceFolder
,
imageId
));
err
!=
nil
{
return
[]
error
{
err
}
return
[]
error
{
err
}
}
}
...
@@ -20,20 +22,26 @@ func ResizeImage(config *Config, imageId string) []error {
...
@@ -20,20 +22,26 @@ func ResizeImage(config *Config, imageId string) []error {
if
originalImage
,
err
=
imgconv
.
NewImage
(
wand
);
err
!=
nil
{
if
originalImage
,
err
=
imgconv
.
NewImage
(
wand
);
err
!=
nil
{
return
[]
error
{
err
}
return
[]
error
{
err
}
}
}
trackTimeSince
(
imageProcessDurationRead
,
startRead
)
return
runMany
(
len
(
config
.
Sizes
),
func
(
index
int
)
error
{
return
runMany
(
len
(
config
.
Sizes
),
func
(
index
int
)
error
{
definition
:=
config
.
Sizes
[
index
]
definition
:=
config
.
Sizes
[
index
]
path
:=
filepath
.
Join
(
config
.
TargetFolder
,
fmt
.
Sprintf
(
"%s%s"
,
imageId
,
definition
.
Suffix
))
path
:=
filepath
.
Join
(
config
.
TargetFolder
,
fmt
.
Sprintf
(
"%s%s"
,
imageId
,
definition
.
Suffix
))
startClone
:=
time
.
Now
()
.
UTC
()
image
:=
originalImage
.
CloneImage
()
image
:=
originalImage
.
CloneImage
()
startCrop
:=
trackTimeSince
(
imageProcessDurationClone
,
startClone
)
if
err
:=
image
.
Crop
(
definition
.
Size
);
err
!=
nil
{
if
err
:=
image
.
Crop
(
definition
.
Size
);
err
!=
nil
{
return
err
return
err
}
}
startResize
:=
trackTimeSince
(
imageProcessDurationCrop
,
startCrop
)
if
err
:=
image
.
Resize
(
definition
.
Size
);
err
!=
nil
{
if
err
:=
image
.
Resize
(
definition
.
Size
);
err
!=
nil
{
return
err
return
err
}
}
startWrite
:=
trackTimeSince
(
imageProcessDurationResize
,
startResize
)
if
err
:=
image
.
Write
(
config
.
Quality
,
path
);
err
!=
nil
{
if
err
:=
image
.
Write
(
config
.
Quality
,
path
);
err
!=
nil
{
return
err
return
err
}
}
trackTimeSince
(
imageProcessDurationWrite
,
startWrite
)
return
nil
return
nil
})
})
}
}
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