Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
lecture materials
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
generic software skills
lecture materials
Commits
f825382f
Commit
f825382f
authored
10 months ago
by
Karl-Hermann Wieners
Browse files
Options
Downloads
Patches
Plain Diff
file/data: review write timing
parent
73df62e7
No related branches found
No related tags found
1 merge request
!11
File and Data Systems
Pipeline
#71273
passed
10 months ago
Stage: test
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lectures/file-and-data-systems/timer.ipynb
+65
-28
65 additions, 28 deletions
lectures/file-and-data-systems/timer.ipynb
with
65 additions
and
28 deletions
lectures/file-and-data-systems/timer.ipynb
+
65
−
28
View file @
f825382f
{
{
"cells": [
"cells": [
{
"cell_type": "markdown",
"id": "14cac4fd",
"metadata": {},
"source": [
"# Measure write behavior"
]
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
1
,
"execution_count":
null
,
"id": "bc0cdf17-1d21-4ade-a090-45101abf8ab5",
"id": "bc0cdf17-1d21-4ade-a090-45101abf8ab5",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"import timeit"
"import getpass\n",
"import os\n",
"import timeit\n",
"\n",
"user = getpass.getuser()\n",
"\n",
"destination = f\"/scratch/{user[0]}/{user}\""
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
2
,
"execution_count":
null
,
"id": "bcf39570-a5bc-4af4-9354-06a801222826",
"id": "bcf39570-a5bc-4af4-9354-06a801222826",
"metadata": {},
"metadata": {},
"outputs": [],
"outputs": [],
"source": [
"source": [
"def write (path, length, blocksize=1024**2):\n",
"def run_write (path, length, blocksize=1024**2):\n",
" with open(path, \"wb\") as of:\n",
"\n",
" data = bytearray(blocksize)\n",
" (times, remainder) = divmod(length, blocksize)\n",
" times = length // (blocksize)\n",
" data = bytearray(blocksize)\n",
" remainder = length % blocksize\n",
"\n",
" for i in range (times):\n",
" of = open(path, \"wb\")\n",
" of.write(data)\n",
" for i in range(times):\n",
" if remainder:\n",
" of.write(data)\n",
" of.write(bytearray(remainder))\n",
" if remainder:\n",
" of.close()"
" of.write(bytearray(remainder))\n",
" of.close()"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count":
3
,
"execution_count":
null
,
"id": "34a59ea9-52c9-4c3f-8664-a5a97882e5e0",
"id": "34a59ea9-52c9-4c3f-8664-a5a97882e5e0",
"metadata": {},
"metadata": {},
"outputs": [
"outputs": [],
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'1GB': 0.5966405299986945}\n"
]
}
],
"source": [
"source": [
"duration = {}\n",
"duration = {}\n",
"duration['1GB'] = timeit.timeit(lambda : write(\"/scratch/k/k202134/test.1GB\", (1024**3)), number =1)\n",
"duration['1GB'] = timeit.timeit(lambda : run_write(f\"{destination}/test.1GB\", (1024**3)), number = 1)\n",
"print (duration)"
"print(duration)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b6b7c16",
"metadata": {},
"outputs": [],
"source": [
"os.remove(f\"{destination}/test.1GB\")"
]
},
{
"cell_type": "markdown",
"id": "b1615912",
"metadata": {},
"source": [
"### Other ideas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "658a2847",
"metadata": {},
"outputs": [],
"source": [
"destination = f\"/dev/shm/{user}\"\n",
"# destination = f\"/tmp/{user}\"\n",
"os.mkdir(destination)"
]
]
}
}
],
],
"metadata": {
"metadata": {
"kernelspec": {
"kernelspec": {
"display_name": "
0
Python 3 (
based on the module python3/unstable
",
"display_name": "Python 3 (
ipykernel)
",
"language": "python",
"language": "python",
"name": "python3
_unstable
"
"name": "python3"
},
},
"language_info": {
"language_info": {
"codemirror_mode": {
"codemirror_mode": {
...
@@ -66,7 +103,7 @@
...
@@ -66,7 +103,7 @@
"name": "python",
"name": "python",
"nbconvert_exporter": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"pygments_lexer": "ipython3",
"version": "3.10.1
0
"
"version": "3.10.1
2
"
}
}
},
},
"nbformat": 4,
"nbformat": 4,
...
...
%% Cell type:markdown id:14cac4fd tags:
# Measure write behavior
%% Cell type:code id:bc0cdf17-1d21-4ade-a090-45101abf8ab5 tags:
%% Cell type:code id:bc0cdf17-1d21-4ade-a090-45101abf8ab5 tags:
```
python
```
python
import
getpass
import
os
import
timeit
import
timeit
user
=
getpass
.
getuser
()
destination
=
f
"
/scratch/
{
user
[
0
]
}
/
{
user
}
"
```
```
%% Cell type:code id:bcf39570-a5bc-4af4-9354-06a801222826 tags:
%% Cell type:code id:bcf39570-a5bc-4af4-9354-06a801222826 tags:
```
python
```
python
def
write
(
path
,
length
,
blocksize
=
1024
**
2
):
def
run_write
(
path
,
length
,
blocksize
=
1024
**
2
):
with
open
(
path
,
"
wb
"
)
as
of
:
data
=
bytearray
(
blocksize
)
(
times
,
remainder
)
=
divmod
(
length
,
blocksize
)
times
=
length
//
(
blocksize
)
data
=
bytearray
(
blocksize
)
remainder
=
length
%
blocksize
for
i
in
range
(
times
):
of
=
open
(
path
,
"
wb
"
)
of
.
write
(
data
)
for
i
in
range
(
times
):
if
remainder
:
of
.
write
(
data
)
of
.
write
(
bytearray
(
remainder
))
if
remainder
:
of
.
close
()
of
.
write
(
bytearray
(
remainder
))
of
.
close
()
```
```
%% Cell type:code id:34a59ea9-52c9-4c3f-8664-a5a97882e5e0 tags:
%% Cell type:code id:34a59ea9-52c9-4c3f-8664-a5a97882e5e0 tags:
```
python
```
python
duration
=
{}
duration
=
{}
duration
[
'
1GB
'
]
=
timeit
.
timeit
(
lambda
:
write
(
"
/scratch/k/k202134/test.1GB
"
,
(
1024
**
3
)),
number
=
1
)
duration
[
'
1GB
'
]
=
timeit
.
timeit
(
lambda
:
run_write
(
f
"
{
destination
}
/test.1GB
"
,
(
1024
**
3
)),
number
=
1
)
print
(
duration
)
print
(
duration
)
```
%% Cell type:code id:6b6b7c16 tags:
```
python
os
.
remove
(
f
"
{
destination
}
/test.1GB
"
)
```
```
%% Output
%% Cell type:markdown id:b1615912 tags:
### Other ideas
{'1GB': 0.5966405299986945}
%% Cell type:code id:658a2847 tags:
```
python
destination
=
f
"
/dev/shm/
{
user
}
"
# destination = f"/tmp/{user}"
os
.
mkdir
(
destination
)
```
...
...
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