Commit 6d7cb63c authored by Administrator's avatar Administrator

adding atomic to test, need to test

parent 4cba2458
{
"metadata": {
"name": "",
"signature": "sha256:2f6110e86a37440203808b564a0f086c8f872ccd2329b1fc5fa7f161780f46f1"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "code",
"collapsed": false,
"input": [
"from node.models import Node, NodeType\n",
"from django.contrib.auth.models import User"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import datetime"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"#number_userIndex = 100\n",
"#number_projectIndex = 50\n",
"#number_documentIndex = 10000\n",
"number_userIndex = 10\n",
"number_projectIndex = 50\n",
"number_documentIndex = 100"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 6
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"NodeType.objects.all().delete()\n",
"nodeTypeRoot = NodeType(name=\"Root\")\n",
"nodeTypeRoot.save()\n",
"nodeTypeProject = NodeType(name=\"Project\")\n",
"nodeTypeProject.save()\n",
"nodeTypeDocument = NodeType(name=\"Document\")\n",
"nodeTypeDocument.save()"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 7
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"t0 = datetime.datetime.now()\n",
"with transaction.atomic():\n",
" for userIndex in range(number_userIndex):\n",
" userName = 'User #%d' % (userIndex, )\n",
" user = User(username=userName)\n",
" user.save()\n",
" rootNode = Node.add_root(name=userName, type_id=nodeTypeRoot.pk, user_id=user.id)\n",
" \n",
" print(userName)\n",
" for projectIndex in range(number_projectIndex):\n",
" projectName = 'Project #%d-%d' % (userIndex, projectIndex, )\n",
" projectNode = Node(name=projectName, type_id=nodeTypeProject.pk, user_id=user.id)\n",
" rootNode.add_child(instance=projectNode)\n",
" documents = [\n",
" {\"data\": {\"name\":'Document #%d-%d-%d' % (userIndex, projectIndex, documentIndex, ), \"type_id\":nodeTypeDocument.pk, \"user_id\":user.id}}\n",
" for documentIndex in range(number_documentIndex)\n",
" ]\n",
" Node.load_bulk(documents, projectNode)\n",
"\n",
"t1 = datetime.datetime.now()\n",
"t1 - t0"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"User #0\n",
"User #1"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #2"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #3"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #4"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #5"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #6"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #7"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #8"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #9"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n"
]
}
],
"prompt_number": 8
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(t1-t0)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"116.94907426834106\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"help(time())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Help on float object:\n",
"\n",
"class float(object)\n",
" | float(x) -> floating point number\n",
" | \n",
" | Convert a string or number to a floating point number, if possible.\n",
" | \n",
" | Methods defined here:\n",
" | \n",
" | __abs__(self, /)\n",
" | abs(self)\n",
" | \n",
" | __add__(self, value, /)\n",
" | Return self+value.\n",
" | \n",
" | __bool__(self, /)\n",
" | self != 0\n",
" | \n",
" | __divmod__(self, value, /)\n",
" | Return divmod(self, value).\n",
" | \n",
" | __eq__(self, value, /)\n",
" | Return self==value.\n",
" | \n",
" | __float__(self, /)\n",
" | float(self)\n",
" | \n",
" | __floordiv__(self, value, /)\n",
" | Return self//value.\n",
" | \n",
" | __format__(...)\n",
" | float.__format__(format_spec) -> string\n",
" | \n",
" | Formats the float according to format_spec.\n",
" | \n",
" | __ge__(self, value, /)\n",
" | Return self>=value.\n",
" | \n",
" | __getattribute__(self, name, /)\n",
" | Return getattr(self, name).\n",
" | \n",
" | __getformat__(...) from builtins.type\n",
" | float.__getformat__(typestr) -> string\n",
" | \n",
" | You probably don't want to use this function. It exists mainly to be\n",
" | used in Python's test suite.\n",
" | \n",
" | typestr must be 'double' or 'float'. This function returns whichever of\n",
" | 'unknown', 'IEEE, big-endian' or 'IEEE, little-endian' best describes the\n",
" | format of floating point numbers used by the C type named by typestr.\n",
" | \n",
" | __getnewargs__(...)\n",
" | \n",
" | __gt__(self, value, /)\n",
" | Return self>value.\n",
" | \n",
" | __hash__(self, /)\n",
" | Return hash(self).\n",
" | \n",
" | __int__(self, /)\n",
" | int(self)\n",
" | \n",
" | __le__(self, value, /)\n",
" | Return self<=value.\n",
" | \n",
" | __lt__(self, value, /)\n",
" | Return self<value.\n",
" | \n",
" | __mod__(self, value, /)\n",
" | Return self%value.\n",
" | \n",
" | __mul__(self, value, /)\n",
" | Return self*value.\n",
" | \n",
" | __ne__(self, value, /)\n",
" | Return self!=value.\n",
" | \n",
" | __neg__(self, /)\n",
" | -self\n",
" | \n",
" | __new__(*args, **kwargs) from builtins.type\n",
" | Create and return a new object. See help(type) for accurate signature.\n",
" | \n",
" | __pos__(self, /)\n",
" | +self\n",
" | \n",
" | __pow__(self, value, mod=None, /)\n",
" | Return pow(self, value, mod).\n",
" | \n",
" | __radd__(self, value, /)\n",
" | Return value+self.\n",
" | \n",
" | __rdivmod__(self, value, /)\n",
" | Return divmod(value, self).\n",
" | \n",
" | __repr__(self, /)\n",
" | Return repr(self).\n",
" | \n",
" | __rfloordiv__(self, value, /)\n",
" | Return value//self.\n",
" | \n",
" | __rmod__(self, value, /)\n",
" | Return value%self.\n",
" | \n",
" | __rmul__(self, value, /)\n",
" | Return value*self.\n",
" | \n",
" | __round__(...)\n",
" | Return the Integral closest to x, rounding half toward even.\n",
" | When an argument is passed, work like built-in round(x, ndigits).\n",
" | \n",
" | __rpow__(self, value, mod=None, /)\n",
" | Return pow(value, self, mod).\n",
" | \n",
" | __rsub__(self, value, /)\n",
" | Return value-self.\n",
" | \n",
" | __rtruediv__(self, value, /)\n",
" | Return value/self.\n",
" | \n",
" | __setformat__(...) from builtins.type\n",
" | float.__setformat__(typestr, fmt) -> None\n",
" | \n",
" | You probably don't want to use this function. It exists mainly to be\n",
" | used in Python's test suite.\n",
" | \n",
" | typestr must be 'double' or 'float'. fmt must be one of 'unknown',\n",
" | 'IEEE, big-endian' or 'IEEE, little-endian', and in addition can only be\n",
" | one of the latter two if it appears to match the underlying C reality.\n",
" | \n",
" | Override the automatic determination of C-level floating point type.\n",
" | This affects how floats are converted to and from binary strings.\n",
" | \n",
" | __str__(self, /)\n",
" | Return str(self).\n",
" | \n",
" | __sub__(self, value, /)\n",
" | Return self-value.\n",
" | \n",
" | __truediv__(self, value, /)\n",
" | Return self/value.\n",
" | \n",
" | __trunc__(...)\n",
" | Return the Integral closest to x between 0 and x.\n",
" | \n",
" | as_integer_ratio(...)\n",
" | float.as_integer_ratio() -> (int, int)\n",
" | \n",
" | Return a pair of integers, whose ratio is exactly equal to the original\n",
" | float and with a positive denominator.\n",
" | Raise OverflowError on infinities and a ValueError on NaNs.\n",
" | \n",
" | >>> (10.0).as_integer_ratio()\n",
" | (10, 1)\n",
" | >>> (0.0).as_integer_ratio()\n",
" | (0, 1)\n",
" | >>> (-.25).as_integer_ratio()\n",
" | (-1, 4)\n",
" | \n",
" | conjugate(...)\n",
" | Return self, the complex conjugate of any float.\n",
" | \n",
" | fromhex(...) from builtins.type\n",
" | float.fromhex(string) -> float\n",
" | \n",
" | Create a floating-point number from a hexadecimal string.\n",
" | >>> float.fromhex('0x1.ffffp10')\n",
" | 2047.984375\n",
" | >>> float.fromhex('-0x1p-1074')\n",
" | -5e-324\n",
" | \n",
" | hex(...)\n",
" | float.hex() -> string\n",
" | \n",
" | Return a hexadecimal representation of a floating-point number.\n",
" | >>> (-0.1).hex()\n",
" | '-0x1.999999999999ap-4'\n",
" | >>> 3.14159.hex()\n",
" | '0x1.921f9f01b866ep+1'\n",
" | \n",
" | is_integer(...)\n",
" | Return True if the float is an integer.\n",
" | \n",
" | ----------------------------------------------------------------------\n",
" | Data descriptors defined here:\n",
" | \n",
" | imag\n",
" | the imaginary part of a complex number\n",
" | \n",
" | real\n",
" | the real part of a complex number\n",
"\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for node in Node.objects.all():\n",
" print(node.name)"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 37
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {}
}
]
}
\ No newline at end of file
{
"metadata": {
"name": "",
"signature": "sha256:1ca21b1538256b8f19a1e8b22af61d6439dd14912f5cd0c4e3eca72da3cea077"
"signature": "sha256:4bf33768886345db6440931d106e00bcaa9db0e0745a364d8e170774d0443d3a"
},
"nbformat": 3,
"nbformat_minor": 0,
......@@ -18,27 +18,34 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 22
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from time import time\n",
"print(time())"
"import datetime"
],
"language": "python",
"metadata": {},
"outputs": [
"outputs": [],
"prompt_number": 2
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"1412775903.5760932\n"
]
}
"cell_type": "code",
"collapsed": false,
"input": [
"#number_userIndex = 100\n",
"#number_projectIndex = 50\n",
"#number_documentIndex = 10000\n",
"number_userIndex = 5\n",
"number_projectIndex = 50\n",
"number_documentIndex = 1000"
],
"prompt_number": 8
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 3
},
{
"cell_type": "code",
......@@ -55,36 +62,73 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 9
"prompt_number": 4
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Node.objects.all().delete()\n",
"User.objects.filter(username__startswith = \"User #\").delete()\n",
"\n",
"t0 = time()\n",
"for userIndex in range(100):\n",
"t0 = datetime.datetime.now()\n",
"with transaction.atomic():\n",
" for userIndex in range(number_userIndex):\n",
" userName = 'User #%d' % (userIndex, )\n",
" user = User(username=userName)\n",
" user.save()\n",
" rootNode = Node.add_root(name=userName, type_id=nodeTypeRoot.pk, user_id=user.id)\n",
" \n",
" print(userName)\n",
" for projectIndex in range(50):\n",
" for projectIndex in range(number_projectIndex):\n",
" projectName = 'Project #%d-%d' % (userIndex, projectIndex, )\n",
" projectNode = Node(name=projectName, type_id=nodeTypeProject.pk, user_id=user.id)\n",
" rootNode.add_child(instance=projectNode)\n",
" documents = [\n",
" {\"data\": {\"name\":'Document #%d-%d-%d' % (userIndex, projectIndex, documentIndex, ), \"type_id\":nodeTypeDocument.pk, \"user_id\":user.id}}\n",
" for documentIndex in range(10000)\n",
" for documentIndex in range(number_documentIndex)\n",
" ]\n",
" Node.load_bulk(documents, projectNode)\n",
"print(time() - t0)"
"\n",
"t1 = datetime.datetime.now()\n",
"t1 - t0"
],
"language": "python",
"metadata": {},
"outputs": []
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"User #0\n",
"User #1"
]
},
{
"output_type": "stream",
"stream": "stdout",
"text": [
"\n",
"User #2"
]
}
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"print(t1-t0)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"116.94907426834106\n"
]
}
],
"prompt_number": 10
},
{
"cell_type": "code",
......
# coding: utf-8
from django.db import transaction
from node.models import Node, NodeType
from models import Node, NodeType
from django.contrib.auth.models import User
from time import time
print(time())
......@@ -20,9 +19,14 @@ nodeTypeProject.save()
nodeTypeDocument = NodeType(name="Document")
nodeTypeDocument.save()
number_userIndex = 100
number_projectIndex = 50
number_documentIndex = 10000
#number_userIndex = 100
#number_projectIndex = 50
#number_documentIndex = 10000
number_userIndex = 10
number_projectIndex = 5
number_documentIndex = 100
# In[ ]:
......@@ -30,7 +34,10 @@ Node.objects.all().delete()
User.objects.filter(username__startswith = "User #").delete()
t0 = time()
for userIndex in range(number_userIndex):
with transaction.atomic():
for userIndex in range(number_userIndex):
userName = 'User #%d' % (userIndex, )
user = User(username=userName)
user.save()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment