Fossil

Check-in [950e54ef]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Adding a simulation (www/collisions.ipynb) for checkin collisions over a working day, given parameters like number of checkins per day. This is in support of discussion on the forum centering on this post: https://fossil-scm.org/forum/forumpost/7349f4b6e1
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 950e54ef35f61b375ef26ce71800dc07f43305eb5da3f658c8556aae78365a65
User & Date: wyoung 2019-06-16 17:58:36
Context
2019-06-16
19:03
Expanded on the rules for literal/verbatim/fenced text in the /md_rules document. check-in: 1b2d6c30 user: wyoung tags: trunk
17:58
Adding a simulation (www/collisions.ipynb) for checkin collisions over a working day, given parameters like number of checkins per day. This is in support of discussion on the forum centering on this post: https://fossil-scm.org/forum/forumpost/7349f4b6e1 check-in: 950e54ef user: wyoung tags: trunk
2019-06-14
19:16
Per forum discussion: when the calculated timestamp of a to-be-touched file is 0, emit a warning and do not set the timestamp. As-yet-uncommitted merges can cause mtime_of_manifest_file() to calculate a time of zero: https://fossil-scm.org/forum/forumpost/6e49ee3725 check-in: 29f450a5 user: stephan tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added www/collisions.ipynb.



















































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Pull in the packages we need"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "require(stats)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Parameters\n",
    "\n",
    "* **cpd** - Checkins per day. Defaults to 20.\n",
    "\n",
    "* **days** - Number of days to simulate.  Defaults to 10000, or roughly\n",
    "    40 working years.\n",
    "\n",
    "* **winSz** - Size of the commit window in percentage of the working day.\n",
    "    Defaults to 0.01% with the default for workSec, which is roughly 3\n",
    "    seconds with the default `workSec` value, a long-ish commit time for Fossil.\n",
    "\n",
    "* **workSec** - Seconds in working day, defaulting to 8 hours.  This value\n",
    "    only affects the reporting output, not the results of the underlying\n",
    "    simulation.  It's a scaling parameter to humanize the results.\n",
    "    \n",
    "* **sd** - The standard deviation to use for our normally-distributed random\n",
    "    numbers. The default gives \"nice\" distributions, spread over the working\n",
    "    day with a low chance of generating values outside the working day.\n",
    "    \n",
    "    The larger this value gets, the more spread out the checkins, and so the\n",
    "    lower the chance of collisions.  You might want to increase it a bit to\n",
    "    simulate early and late workers.  (e.g. `workSec / 3`)\n",
    "    \n",
    "    As you decrease this value — e.g. `workSec / 5` — you're simulating a work\n",
    "    environment where people tend to check their work in closer and closer\n",
    "    to mid-day, which increases the chance of collision.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "collisions <- function(\n",
    "        cpd = 20,\n",
    "        days = 10000,\n",
    "        winSz = 0.01 / 100,\n",
    "        workSec = 8 * 60 * 60,\n",
    "        sd = workSec / 4)\n",
    "{\n",
    "    cat(\"Running simulation...\\n\")\n",
    "\n",
    "    day = 0\n",
    "    collisions = 0\n",
    "    winSec = workSec * winSz\n",
    "    mean = workSec / 2\n",
    "\n",
    "    while (day < days) {\n",
    "        # Create the commit time vector as random values in a normal\n",
    "        # distribution.\n",
    "        times = sort(rnorm(cpd, mean, sd))\n",
    "\n",
    "        # Are there any pairs in the time vector that are within the\n",
    "        # passed window size?  If so, that's a Fossil checkin collision.\n",
    "        i = 1\n",
    "        while (i < cpd) {\n",
    "            if (abs(times[i] - times[i + 1]) < winSec) {\n",
    "                collisions = collisions + 1\n",
    "            }\n",
    "            i = i + 1\n",
    "        }\n",
    "        \n",
    "        day = day + 1\n",
    "    }\n",
    "    \n",
    "    cat(\"Found\", collisions, \"collisions in\", days, (workSec / 3600),\n",
    "        \"hour working days with\", winSec, \"second windows.\\n\")\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running simulation...\n",
      "Found 423 collisions in 10000 8 hour working days with 2.88 second windows.\n"
     ]
    }
   ],
   "source": [
    "collisions()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "R",
   "language": "R",
   "name": "ir"
  },
  "language_info": {
   "codemirror_mode": "r",
   "file_extension": ".r",
   "mimetype": "text/x-r-source",
   "name": "R",
   "pygments_lexer": "r",
   "version": "3.3.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}