Skip to content

Commit a1a13a9

Browse files
add ruby demo (#53)
## Summary Added a simple Ruby demo along with the corresponding Dockerfile and deployment.yaml. The Ruby code performs nested function calls and checks the first 1000 numbers for primes. It's a simple and effective way to give the CPU a bit of work. --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 1ec00c9 commit a1a13a9

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

ruby/Dockerfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM ruby:bullseye
2+
3+
COPY ./app.rb /tmp
4+
5+
CMD ["ruby", "/tmp/app.rb"]

ruby/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: build
2+
build:
3+
docker build -t parca-demo:ruby .

ruby/app.rb

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
require 'prime'
2+
require 'fileutils'
3+
4+
STDOUT.sync = true
5+
6+
def a(n)
7+
b(n)
8+
end
9+
10+
def b(n)
11+
## Make some calculations
12+
i = 100_000
13+
while i > 0 do
14+
Prime.prime?(i)
15+
i -= 1
16+
end
17+
c(n)
18+
end
19+
20+
def c(n)
21+
## Create a new file
22+
File.open("test.txt", "w") do |f|
23+
f.write("Hello, world!")
24+
end
25+
## Pass new file to d
26+
d("test.txt")
27+
end
28+
29+
def d(file)
30+
## Read file
31+
File.open(file, "r") do |f|
32+
## Print file contents and time
33+
puts f.read + " :: " + Time.now.to_s
34+
end
35+
f(file)
36+
end
37+
38+
def f(file)
39+
## Delete file
40+
File.delete(file)
41+
end
42+
43+
## Infinte loop
44+
while true
45+
sleep(1)
46+
a(1)
47+
end

ruby/deployment.yaml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
labels:
5+
app.kubernetes.io/name: demo-ruby
6+
name: ruby
7+
namespace: parca
8+
spec:
9+
replicas: 3
10+
selector:
11+
matchLabels:
12+
app.kubernetes.io/name: demo-ruby
13+
template:
14+
metadata:
15+
labels:
16+
app.kubernetes.io/name: demo-ruby
17+
spec:
18+
containers:
19+
- image: parca-demo:ruby
20+
name: python
21+
resources:
22+
limits:
23+
cpu: "100m"
24+
memory: "256Mi"

0 commit comments

Comments
 (0)