Skip to content

Commit

Permalink
Merge pull request #333 from alcidesmig/master
Browse files Browse the repository at this point in the history
feat(socialNetwork): hpa for deployments & improve wrk2 instructions
  • Loading branch information
cdelimitrou authored Jun 27, 2024
2 parents 223da8a + a0f430a commit 07bb6e7
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 12 deletions.
22 changes: 19 additions & 3 deletions socialNetwork/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,41 @@ docker stack deploy --compose-file=docker-compose-swarm.yml <service-name>
### Register users and construct social graphs

Register users and construct social graph by running
`python3 scripts/init_social_graph.py --graph=<socfb-Reed98, ego-twitter, or soc-twitter-follows-mun>`. It will initialize a social graph from a small social network [Reed98 Facebook Networks](http://networkrepository.com/socfb-Reed98.php), a medium social network [Ego Twitter](https://snap.stanford.edu/data/ego-Twitter.html), or a large social network [TWITTER-FOLLOWS-MUN](https://networkrepository.com/soc-twitter-follows-mun.php).
`python3 scripts/init_social_graph.py --graph=<socfb-Reed98, ego-twitter, or soc-twitter-follows-mun>`. It will initialize a social graph from a small social network [Reed98 Facebook Networks](http://networkrepository.com/socfb-Reed98.php), a medium social network [Ego Twitter](https://snap.stanford.edu/data/ego-Twitter.html), or a large social network [TWITTER-FOLLOWS-MUN](https://networkrepository.com/soc-twitter-follows-mun.php). If your setup is not local, you can specify the IP and port of the nginx through `--ip` and `--port` flags, respectively.

### Running HTTP workload generator

#### Make

It is necessary to build the workload generator tool. Thus, please assert that:
1. Your repository was cloned using `--recurse-submodules` or you pulled the submodules after the clone using `git submodule update --init --recursive`
2. You have the "luajit", "luasocket", "libssl-dev" and "make" packages installed.
3. You are not running inside arm

With the dependencies fulfilled, you can run:

```bash
# There are two wrk2 folders: one in the root of the repository and one inside the socialNetwork folder. This is the first one.
cd ../wrk2
# Compile
make
```
back to socialNetwork

And then go back to the socialNetwork folder to run the wrk2 properly for the system.
```bash
# Back to socialNetwork, in the root folder.
cd ../socialNetwork
```

#### Compose posts

```bash
../wrk2/wrk -D exp -t <num-threads> -c <num-conns> -d <duration> -L -s ./wrk2/scripts/social-network/compose-post.lua http://localhost:8080/wrk2-api/post/compose -R <reqs-per-sec>
../wrk2/wrk -D exp -t <num-threads> -c <num-conns> -d <duration> -L -s ./wrk2/scripts/social-network/compose-post.lua http://<nginx-ip>:8080/wrk2-api/post/compose -R <reqs-per-sec>
```

Example:
```bash
../wrk2/wrk -D exp -t 12 -c 400 -d 300 -L -s ./wrk2/scripts/social-network/compose-post.lua http://10.109.126.103:8080/wrk2-api/post/compose -R 10
```

#### Read home timelines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ spec:
- {{ $arg }}
{{- end -}}
{{- end }}
{{- if .resources }}
{{- if hasKey . "resources" }}
resources:
{{ tpl .resources $ | nindent 10 | trim }}
{{ toYaml .resources | nindent 10 | trim }}
{{- else if hasKey $.Values.global "resources" }}
resources:
{{ tpl $.Values.global.resources $ | nindent 10 | trim }}
{{ toYaml $.Values.global.resources | nindent 10 | trim }}
{{- end }}
{{- if $.Values.configMaps }}
volumeMounts:
Expand All @@ -77,4 +77,5 @@ spec:
hostname: {{ $.Values.name }}
restartPolicy: {{ .Values.restartPolicy | default .Values.global.restartPolicy}}

{{- end}}
{{ include "socialnetwork.templates.baseHPA" . }}
{{- end}}
50 changes: 50 additions & 0 deletions socialNetwork/helm-chart/socialnetwork/templates/_baseHPA.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{{- define "socialnetwork.templates.baseHPA" }}

{{- if or (and .Values.hpa .Values.hpa.enabled) ($.Values.global.hpa.enabled) -}}
---
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Values.name }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Values.name }}
{{- if and .Values.hpa .Values.hpa.minReplicas}}
minReplicas: {{ .Values.hpa.minReplicas }}
{{- else}}
minReplicas: {{ default 1 .Values.global.hpa.minReplicas }}
{{- end}}
{{- if and .Values.hpa .Values.hpa.maxReplicas}}
maxReplicas: {{ .Values.hpa.maxReplicas }}
{{- else}}
maxReplicas: {{ default 1 .Values.global.hpa.maxReplicas }}
{{- end}}
metrics:
{{- if or $.Values.global.hpa.targetMemoryUtilizationPercentage (and .Values.hpa .Values.hpa.targetMemoryUtilizationPercentage) }}
- type: Resource
resource:
name: memory
target:
type: Utilization
{{- if and .Values.hpa .Values.hpa.targetMemoryUtilizationPercentage }}
averageUtilization: {{ .Values.hpa.targetMemoryUtilizationPercentage }}
{{- else }}
averageUtilization: {{ $.Values.global.hpa.targetMemoryUtilizationPercentage }}
{{- end}}
{{- end }}
{{- if or $.Values.global.hpa.targetCPUUtilizationPercentage (and .Values.hpa .Values.hpa.targetCPUUtilizationPercentage) }}
- type: Resource
resource:
name: cpu
target:
type: Utilization
{{- if and .Values.hpa .Values.hpa.targetCPUUtilizationPercentage }}
averageUtilization: {{ .Values.hpa.targetCPUUtilizationPercentage }}
{{- else }}
averageUtilization: {{ $.Values.global.hpa.targetCPUUtilizationPercentage }}
{{- end}}
{{- end }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ spec:
{{- end }}
{{- if .resources }}
resources:
{{ tpl .resources $ | nindent 10 | trim }}
{{ toYaml .resources | nindent 10 | trim }}
{{- else if hasKey $.Values.global "resources" }}
resources:
{{ tpl $.Values.global.resources $ | nindent 10 | trim }}
{{ toYaml $.Values.global.resources | nindent 10 | trim }}
{{- end }}
{{- if $.Values.configMaps }}
volumeMounts:
Expand All @@ -74,10 +74,10 @@ spec:
{{- end -}}
{{- if .resources }}
resources:
{{ tpl .resources $ | nindent 10 | trim }}
{{ toYaml .resources | nindent 10 | trim }}
{{- else if hasKey $.Values.global "resources" }}
resources:
{{ tpl $.Values.global.resources $ | nindent 10 | trim }}
{{ toYaml $.Values.global.resources | nindent 10 | trim }}
{{- end }}
{{- if .env }}
env:
Expand Down Expand Up @@ -122,4 +122,5 @@ spec:
hostname: {{ $.Values.name }}
restartPolicy: {{ .Values.restartPolicy | default .Values.global.restartPolicy}}

{{- end}}
{{ include "socialnetwork.templates.baseHPA" . }}
{{- end}}
13 changes: 13 additions & 0 deletions socialNetwork/helm-chart/socialnetwork/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,17 @@
global:
hpa:
enabled: false
minReplicas: 1
maxReplicas: 10
targetMemoryUtilizationPercentage: '60'
targetCPUUtilizationPercentage: '60'
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 100m
memory: 128Mi
replicas: 1
imagePullPolicy: "IfNotPresent"
restartPolicy: Always
Expand Down

0 comments on commit 07bb6e7

Please sign in to comment.