Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Suggestible
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
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
open-source
Suggestible
Commits
c6887e19
Commit
c6887e19
authored
7 months ago
by
Phil Höfer
Browse files
Options
Downloads
Patches
Plain Diff
Implement Basic Incremental Startup
parent
57df97e2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#10082
passed
7 months ago
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
chart/templates/deployment.yaml
+17
-1
17 additions, 1 deletion
chart/templates/deployment.yaml
src/main.rs
+22
-15
22 additions, 15 deletions
src/main.rs
with
39 additions
and
16 deletions
chart/templates/deployment.yaml
+
17
−
1
View file @
c6887e19
...
@@ -54,15 +54,31 @@ spec:
...
@@ -54,15 +54,31 @@ spec:
-
name
:
http
-
name
:
http
containerPort
:
8000
containerPort
:
8000
protocol
:
TCP
protocol
:
TCP
startupProbe
:
httpGet
:
path
:
/healthz
port
:
http
initialDelaySeconds
:
10
periodSeconds
:
5
timeoutSeconds
:
1
livenessProbe
:
livenessProbe
:
httpGet
:
httpGet
:
path
:
/healthz
path
:
/healthz
port
:
http
port
:
http
initialDelaySeconds
:
20
periodSeconds
:
20
timeoutSeconds
:
5
successThreshold
:
1
failureThreshold
:
3
readinessProbe
:
readinessProbe
:
httpGet
:
httpGet
:
path
:
/healthz
path
:
/healthz
port
:
http
port
:
http
timeoutSeconds
:
20
initialDelaySeconds
:
20
periodSeconds
:
5
timeoutSeconds
:
1
successThreshold
:
1
failureThreshold
:
3
resources
:
resources
:
{{
- toYaml .Values.resources | nindent 12
}}
{{
- toYaml .Values.resources | nindent 12
}}
{{
- with .Values.nodeSelector
}}
{{
- with .Values.nodeSelector
}}
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
22
−
15
View file @
c6887e19
// SPDX-FileCopyrightText: 2024 Phil Höfer <phil@suma-ev.de>
// SPDX-FileCopyrightText: 2024 Phil Höfer <phil@suma-ev.de>
// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-License-Identifier: AGPL-3.0-only
use
core
::
str
;
use
core
::
{
str
,
time
}
;
use
std
::
collections
::
HashMap
;
use
std
::
collections
::
HashMap
;
use
std
::
fs
::
File
;
use
std
::
fs
::
File
;
use
std
::
io
::{
self
,
BufRead
,
BufReader
};
use
std
::
io
::{
self
,
BufRead
,
BufReader
};
...
@@ -93,14 +93,32 @@ fn main() -> Result<(), io::Error> {
...
@@ -93,14 +93,32 @@ fn main() -> Result<(), io::Error> {
let
server
=
Server
::
http
(
"0.0.0.0:8000"
)
.unwrap
();
let
server
=
Server
::
http
(
"0.0.0.0:8000"
)
.unwrap
();
for
request
in
server
.incoming_requests
()
{
loop
{
process_request
(
request
,
config
.clone
(),
&
mut
markov_chain
,
last_update
,
last_decay
)
let
request
=
server
.recv_timeout
(
std
::
time
::
Duration
::
from_secs
(
10
));
match
request
{
Ok
(
Some
(
r
))
=>
{
process_request
(
r
,
config
.clone
(),
&
mut
markov_chain
);
},
_
=>
{
let
now
=
std
::
time
::
SystemTime
::
now
();
let
update_elapsed
=
now
.duration_since
(
last_update
)
.expect
(
"Time went backwards"
);
if
update_elapsed
>=
std
::
time
::
Duration
::
from_secs
(
2
*
60
*
60
)
||
(
markov_chain
.update_count
()
<
10000
)
{
//every 2h
read_from_db
(
config
.clone
(),
&
mut
markov_chain
);
last_update
=
now
;
}
let
decay_elapsed
=
now
.duration_since
(
last_decay
)
.expect
(
"Time went backwards"
);
if
decay_elapsed
>=
std
::
time
::
Duration
::
from_secs
(
24
*
60
*
60
)
||
(
markov_chain
.update_count
()
<
1000
)
{
//every 24h
markov_chain
.decay
();
last_decay
=
now
;
}
}
}
}
}
Ok
(())
Ok
(())
}
}
fn
process_request
(
request
:
tiny_http
::
Request
,
config
:
HashMap
<
String
,
String
>
,
markov_chain
:
&
mut
CompositePredictor
,
mut
last_update
:
SystemTime
,
mut
last_decay
:
SystemTime
)
{
fn
process_request
(
request
:
tiny_http
::
Request
,
config
:
HashMap
<
String
,
String
>
,
markov_chain
:
&
mut
CompositePredictor
)
{
// println!("received request! method: {:?}, url: {:?}, headers: {:?}",
// println!("received request! method: {:?}, url: {:?}, headers: {:?}",
// request.method(),
// request.method(),
// request.url(),
// request.url(),
...
@@ -142,17 +160,6 @@ fn process_request(request: tiny_http::Request, config: HashMap<String, String>,
...
@@ -142,17 +160,6 @@ fn process_request(request: tiny_http::Request, config: HashMap<String, String>,
let
response
=
Response
::
from_string
(
let
response
=
Response
::
from_string
(
format!
(
"[
\"
{}
\"
,[{}]]"
,
query
,
predictions
.join
(
","
)));
format!
(
"[
\"
{}
\"
,[{}]]"
,
query
,
predictions
.join
(
","
)));
request
.respond
(
response
);
request
.respond
(
response
);
let
now
=
std
::
time
::
SystemTime
::
now
();
let
update_elapsed
=
now
.duration_since
(
last_update
)
.expect
(
"Time went backwards"
);
if
update_elapsed
>=
std
::
time
::
Duration
::
from_secs
(
2
*
60
*
60
)
||
(
markov_chain
.update_count
()
<
10000
)
{
//every 2h
read_from_db
(
config
.clone
(),
markov_chain
);
last_update
=
now
;
}
let
decay_elapsed
=
now
.duration_since
(
last_decay
)
.expect
(
"Time went backwards"
);
if
decay_elapsed
>=
std
::
time
::
Duration
::
from_secs
(
24
*
60
*
60
)
||
(
markov_chain
.update_count
()
<
10000
)
{
//every 24h
markov_chain
.decay
();
last_decay
=
now
;
}
},
},
Err
(
e
)
=>
{
Err
(
e
)
=>
{
//println!("Error: {}",e);
//println!("Error: {}",e);
...
...
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