Posts for: #Django

PyAMF django test client



有用 PyAMF 來和 flash 坐資料傳輸,在寫 Django 的 test case,還要另外把 dev server 跑起來,才可以跑測試,這是一個,Unittest 的 test client 直接可以像 Django django.test.client 裡的 Client 直接對應 url 的方式來跑

http://hg.io/madssj/pyamf-django-testclient/src/tip/client.py


如果,不用 unitetest 用簡潔的 nose 寫 test case 可以把他所有的 self.logger 的程式標成註解


from django.test.client import Client

client = PyAMFClient(Client(), ‘/your_gateway_url/’)
service = client.getService(‘your_service’)


也可以直接跑 test case

ORM level cache 的選擇

在寫 Django 的應用程式常常會自己硬作一堆 cache 或是 timeout 的機制,有時候,可以看看別人怎麼作

這兩的專案的 code 的等級都不錯,可以由程式學到很多觀念

Johny-cache

http://bitbucket.org/jmoiron/johnny-cache

http://packages.python.org/johnny-cache/

Django Cache Machine

http://github.com/jbalogh/django-cache-machine

http://jbalogh.me/projects/cache-machine/

Django with PayPal



要接付對大家最方便的應該還是 PayPal,畢竟,他運行的時間比較久

基本的方式, Web Form 或是 API 的方式,可以直接用 djangosnippets 的程式範例

http://djangosnippets.org/tags/paypal/

在加上 http://uswaretech.com/blog/2008/11/using-paypal-with-django/

這樣,很快就可以用啦

Web Form (PayNow),基本上,基本的元素

這是由文件的範例



但是我會再加上(加到 web form 裡)

input type=“hidden” name=“rm” value=“2”
input type=“hidden” name=“return” value=“http://somewhere after payment”
input type=“hidden” name=“cancel_return” value=“http://user cancel”>
input type=“hidden” name=“notify_url” value=“http://url to handle Paypal callback”



API

就直接照上面國外部落格作者寫得的就可以了

買了 2host 512 RAM XEN VPS

2010-06-29 更正,實際分數跑起來,不算高,我問問看客服,有沒有官方的數據可以比較,還是要多比較一下,我會再看看 Linode 的

便宜又大碗,先用用看,目前還蠻穩定的,連台灣,網路還算 OK

我是選 512M的 VPS 一個月 8 塊美金左右,大概比我自己擺 server 的電費還省,下面是 CPU info 可以參考一下,不過,我自己跑起來實測,有比 Amazon em2 的最便宜的 small instance 大約快兩倍,不過就比不過 middle 的了,如果有問題就發問吧

跑了 nginx,mysql ,兩個 Django site 大概用了 150M RAM

cat /proc/cpuinfo
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 26
model name : Intel(R) Xeon(R) CPU E5520 @ 2.27GHz
stepping : 5
cpu MHz : 2260.998
cache size : 8192 KB
physical id : 3
siblings : 1
core id : 0
cpu cores : 1
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags : fpu tsc msr pae mce cx8 apic mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm syscall nx lm constant_tsc pni monitor ds_cpl vmx est tm2 cx16 xtpr lahf_lm
bogomips : 5655.56
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

========================================================================
BYTE UNIX Benchmarks (Version 5.1.2)

System: www.digez.com: GNU/Linux
OS: GNU/Linux – 2.6.18-164.15.1.el5xen – #1 SMP Wed Mar 17 12:04:23 EDT 2010
Machine: x86_64 (unknown)
Language: en_US.utf8 (charmap=“UTF-8”, collate=“UTF-8”)
CPU 0: Intel(R) Xeon(R) CPU E5520 @ 2.27GHz (5662.0 bogomips)
Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET, Intel virtualization
CPU 1: Intel(R) Xeon(R) CPU E5520 @ 2.27GHz (5662.0 bogomips)
Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET, Intel virtualization
CPU 2: Intel(R) Xeon(R) CPU E5520 @ 2.27GHz (5662.0 bogomips)
CPU 3: Intel(R) Xeon(R) CPU E5520 @ 2.27GHz (5662.0 bogomips)
Hyper-Threading, x86-64, MMX, Physical Address Ext, SYSCALL/SYSRET, Intel virtualization
14:53:21 up 2:44, 3 users, load average: 0.11, 0.09, 0.07; runlevel 3

————————————————————————
Benchmark Run: Tue Jun 29 2010 14:53:21 - 15:21:28
4 CPUs in system; running 1 parallel copy of tests

Dhrystone 2 using register variables 9705725.4 lps (10.0 s, 7 samples)
Double-Precision Whetstone 2545.7 MWIPS (9.2 s, 7 samples)
Execl Throughput 1004.9 lps (30.0 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks 194004.6 KBps (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks 50378.3 KBps (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks 530237.1 KBps (30.0 s, 2 samples)
Pipe Throughput 340164.4 lps (10.0 s, 7 samples)
Pipe-based Context Switching 68815.1 lps (10.0 s, 7 samples)
Process Creation 2548.5 lps (30.0 s, 2 samples)
Shell Scripts (1 concurrent) 2485.8 lpm (60.0 s, 2 samples)
Shell Scripts (8 concurrent) 582.7 lpm (60.0 s, 2 samples)
System Call Overhead 366327.5 lps (10.0 s, 7 samples)
System Benchmarks Index Values BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 9705725.4 831.7
Double-Precision Whetstone 55.0 2545.7 462.9
Execl Throughput 43.0 1004.9 233.7
File Copy 1024 bufsize 2000 maxblocks 3960.0 194004.6 489.9
File Copy 256 bufsize 500 maxblocks 1655.0 50378.3 304.4
File Copy 4096 bufsize 8000 maxblocks 5800.0 530237.1 914.2
Pipe Throughput 12440.0 340164.4 273.4
Pipe-based Context Switching 4000.0 68815.1 172.0
Process Creation 126.0 2548.5 202.3
Shell Scripts (1 concurrent) 42.4 2485.8 586.3
Shell Scripts (8 concurrent) 6.0 582.7 971.1
System Call Overhead 15000.0 366327.5 244.2
========
System Benchmarks Index Score 398.9

————————————————————————
Benchmark Run: Tue Jun 29 2010 15:21:28 - 15:50:39
4 CPUs in system; running 4 parallel copies of tests

Dhrystone 2 using register variables 36206722.0 lps (10.0 s, 7 samples)
Double-Precision Whetstone 10039.4 MWIPS (9.0 s, 7 samples)
Execl Throughput 2053.0 lps (29.5 s, 2 samples)
File Copy 1024 bufsize 2000 maxblocks 139297.5 KBps (30.0 s, 2 samples)
File Copy 256 bufsize 500 maxblocks 39443.2 KBps (30.0 s, 2 samples)
File Copy 4096 bufsize 8000 maxblocks 413460.4 KBps (30.0 s, 2 samples)
Pipe Throughput 794207.7 lps (10.1 s, 7 samples)
Pipe-based Context Switching 197504.1 lps (10.0 s, 7 samples)
Process Creation 3082.2 lps (30.0 s, 2 samples)
Shell Scripts (1 concurrent) 3750.5 lpm (60.0 s, 2 samples)
Shell Scripts (8 concurrent) 498.9 lpm (60.2 s, 2 samples)
System Call Overhead 848080.4 lps (10.0 s, 7 samples)

System Benchmarks Index Values BASELINE RESULT INDEX
Dhrystone 2 using register variables 116700.0 36206722.0 3102.5
Double-Precision Whetstone 55.0 10039.4 1825.4
Execl Throughput 43.0 2053.0 477.4
File Copy 1024 bufsize 2000 maxblocks 3960.0 139297.5 351.8
File Copy 256 bufsize 500 maxblocks 1655.0 39443.2 238.3
File Copy 4096 bufsize 8000 maxblocks 5800.0 413460.4 712.9
Pipe Throughput 12440.0 794207.7 638.4
Pipe-based Context Switching 4000.0 197504.1 493.8
Process Creation 126.0 3082.2 244.6
Shell Scripts (1 concurrent) 42.4 3750.5 884.5
Shell Scripts (8 concurrent) 6.0 498.9 831.6
System Call Overhead 15000.0 848080.4 565.4
========
System Benchmarks Index Score 645.0


===================================================================================

BYTE UNIX Benchmarks (Version 4.1-wht.2)
System – Linux www.?????.com 2.6.18-164.15.1.el5xen #1 SMP Wed Mar 17 12:04:23 EDT 2010 x86_64 GNU/Linux
/dev/sda1 10321208 2974096 6822824 31% /

Start Benchmark Run: Tue Jun 29 17:17:07 CST 2010
17:17:07 up 5:08, 3 users, load average: 0.19, 0.17, 0.21

End Benchmark Run: Tue Jun 29 17:27:23 CST 2010
17:27:23 up 5:18, 3 users, load average: 16.73, 7.01, 3.15


INDEX VALUES
TEST BASELINE RESULT INDEX

Dhrystone 2 using register variables 376783.7 10227540.3 271.4
Double-Precision Whetstone 83.1 1484.0 178.6
Execl Throughput 188.3 1972.1 104.7
File Copy 1024 bufsize 2000 maxblocks 2672.0 108726.0 406.9
File Copy 256 bufsize 500 maxblocks 1077.0 35313.0 327.9
File Read 4096 bufsize 8000 maxblocks 15382.0 1262429.0 820.7
Pipe-based Context Switching 15448.6 230394.6 149.1
Pipe Throughput 111814.6 1214489.5 108.6
Process Creation 569.3 3573.8 62.8
Shell Scripts (8 concurrent) 44.8 591.7 132.1
System Call Overhead 114433.5 1044142.2 91.2
=========
FINAL SCORE 181.0




redis-benchmark

====== PING ======
10024 requests completed in 0.29 seconds
50 parallel clients
3 bytes payload
keep alive: 1

8.30% <= 0 milliseconds
64.88% <= 1 milliseconds
85.17% <= 2 milliseconds
99.87% <= 3 milliseconds
100.00% <= 4 milliseconds
34328.77 requests per second

====== PING (multi bulk) ======
10011 requests completed in 0.22 seconds
50 parallel clients
3 bytes payload
keep alive: 1

10.27% <= 0 milliseconds
82.24% <= 1 milliseconds
99.25% <= 2 milliseconds
99.90% <= 3 milliseconds
100.00% <= 4 milliseconds
45094.59 requests per second
====== SET ======
10001 requests completed in 0.23 seconds
50 parallel clients
3 bytes payload
keep alive: 1

8.30% <= 0 milliseconds
83.05% <= 1 milliseconds
99.10% <= 2 milliseconds
99.33% <= 3 milliseconds
99.36% <= 4 milliseconds
99.39% <= 5 milliseconds
99.42% <= 6 milliseconds
99.44% <= 7 milliseconds
99.47% <= 8 milliseconds
99.49% <= 9 milliseconds
99.80% <= 10 milliseconds
100.00% <= 11 milliseconds
43294.37 requests per second

====== GET ======
10001 requests completed in 0.23 seconds
50 parallel clients
3 bytes payload
keep alive: 1

8.78% <= 0 milliseconds
83.75% <= 1 milliseconds
99.21% <= 2 milliseconds
99.51% <= 3 milliseconds
99.64% <= 7 milliseconds
99.83% <= 8 milliseconds
100.00% <= 9 milliseconds
43672.49 requests per second

Google appengine 整理

目前,用來開發 google app 上的 Django 小整理

必備套件

Google App Engine Python SDK

http://code.google.com/appengine/downloads.html

Django 開發方式


Google 官方文件
http://code.google.com/appengine/articles/appengine_helper_for_django.html

Google App Engine Helper for Django

http://code.google.com/p/google-app-engine-django/

非官方,可是好用
djangoappengine