Django community: RSS
This page, updated regularly, aggregates Community blog posts from the Django community.
-
Hola, Argentina!
I'll be arriving in Argentina on August 14th. I'll be speaking at PyDay Mendoza on August 15th, and sprinting on August 16th on something Audrey and I named the "new library sprint" (more details to come). On August 22nd, I'll be speaking at the combined Buenos Aires Python, Django, and PyLadies Argentina meetup. Between the events I'll be working from the Eventbrite/Eventioz Argentina office. I'm extremely excited. I've wanted to go to Argentina for years. It's a beautiful country filled with magnificent culture, lovely architecture, great food, superb wine, and wonderful people. Speaking of which, I can't wait to finally put faces to people I've gotten to know over the internet. Hasta pronto! -
Hola, Argentina!
I'll be arriving in Argentina on August 14th. I'll be speaking at PyDay Mendoza on August 15th, and sprinting on August 16th on something Audrey and I named the "new library sprint" (more details to come). On August 22nd, I'll be speaking at the combined Buenos Aires Python, Django, and PyLadies Argentina meetup. Between the events I'll be working from the _Eventbrite / _Eventioz Argentina office. I'm extremely excited. I've wanted to go to Argentina for years. It's a beautiful country filled with magnificent culture, lovely architecture, great food, superb wine, and wonderful people. Speaking of which, I can't wait to finally put faces to people I've gotten to know over the internet. Hasta pronto! -
Review: Django Essentials
A month ago Dyson D'Souza from PacktPub approached me asking if I would be interested in reviewing Django Essentials. I am using Django for some time now - somewhen pre 0.96, I remember the 0.96 release for some reason, I think it was the length of the release cycle but I am not sure anymore - and I really wanted to see how the introduction resources changed, so this was a good chance. Samuel Dauzon does a really good job writing for people who are just starting to work with Django. Beside some history he manages to explain all important concepts and, this is something I especially like, transports them to the terminology used by Django. After explaining what MVC is he also explains what Django is calling the different parts and how they fit together. This is something I often missed when reading a blog post or skimming through another book. While it is a good introduction you should already now a little bit of Python to feel comfortable. The book is suggesting Python 3 which is in my opinion still a risky route to take for a beginner. While most libraries are ported you can still easily run … -
Review: Django Essentials
Review: Django Essentials A month ago Dyson D'Souza from PacktPub approached me asking if I would be interested in reviewing Django Essentials. I am using Django for some time now - somewhen pre 0.96, I remember the 0.96 release for some reason, I think it was the length of the release cycle but I am not sure anymore - and I really wanted to see how the introduction resources changed, so this was a good chance. Samuel Dauzon does a really good job writing for people who are just starting to work with Django. Beside some history he manages to explain all important concepts and, this is something I especially like, transports them to the terminology used by Django. After explaining what MVC is he also explains what Django is calling the different parts and how they fit together. This is something I often missed when reading a blog post or skimming through another book. While it is a good introduction you should already now a little bit of Python to feel comfortable. The book is suggesting Python 3 which is in my opinion still a risky route to take for a beginner. While most libraries are ported you can … -
Starting with django-allauth
There are a lot of ways to do authentication in django. You can do social authentication and/or django.contrib.auth authentication. Generally they are separate, but with django-allauth you can combine them both into one package. It even gives you a great jumping off place with plenty of other features. In this video learn how to start using django-allauth.Watch Now... -
Review Django Essentials
[Django Essentials](http://www.packtpub.com/web-development/getting-started-django). Note it appears the name of this book has been changed from "Getting started with Django". I'll be clear from the outset: I have some pretty strong issues about the first part of this book, and I'm going to be quite specific with the things that I think are wrong with it. Having said that, the later chapters are far better than the earlier ones. I am not sure, however, that it's any more accessible than the [official documentation](http://docs.djangoproject.org). There's probably a market for a more thorough tutorial than the one on the Django website, however, I'm not sure this book, as it stands, is that tutorial. How could this book be better? I think it gets bogged down providing detail in areas that are just not that important at that point in time. I also think it misses a good overview of the product that is being built: indeed it's never clear, even after completing the book, exactly what the product is supposed to do. In my opinion, the code examples are hard to read. This is a combination of the styling of the source code, and the layout. That bold, blue is quite jarring in comparison … -
Don't touch autocommit in Django
Great Sentry We have a sentry service running on our server. It’s built on the Django framework and helps us to monitor the logging messages. It works just like a charm. Disk out of usage However, after three months the service went online, suddenly our IT monitor system alerts that the disk is running out due to mysql, and the mysql is for sentry. 60G /var/lib/mysql/ibdata1 The ibdata1 continuously grows without purge. It contains huge MVCC data like UNDO_LOG, We have to dump/load the whole databases and set innodb_file_per_table to replace the big ibdata1 file. find the exception The dump is very slow, so I take a look at the data. I suprisely find the table sentry_message have 500M rows! most of them is like this - MySQLdb.connections in defaulterrorhandler DatabaseError: (1305, 'SAVEPOINT s47569297779632_x1 does not exist') episode And it’s for an invisible project - Sentry (Internal). What, invisible? Yes, because the our setup didn’t create a default superuser. Thanks mwaterfall, I use the following command to fix it. sentry --config=~/etc/sentry/sentry.conf.py repair --owner=mwaterfall show queries So back to the topic, where is the exception coming from? I open general log for mysql, and see the following 140806 11:01:32 2 Connect … -
Dance my puppets
In many traditional multiplayer text engines for MUD/MUSH/MU*, the player connects to the game with an account name that also becomes their character's in-game name. When they log into the game they immediately "become" that character. If they want to play with another character, they need to create a new account.A single-login system is easy to implement but many code bases try to expand with some sort of "account system" where a single login "account" will allow you to manage one or more game characters. Matthew “Chaos” Sheahan beautifully argues for the benefits of an account system in the April issue of Imaginary Realities; you can read his article here.Evennia and account systemsFirst a brief show of how Evennia handles this. We use the following separation:Session(s) <-> Player <-> Objects/Characters(s)The Session object represents individual client connections to Evennia. The Player is our "account" object. It holds the password hash and your login name but has no in-game existence. Finally we have Objects, the most common being a subclass of Object we call Character. Objects exist in the game. They are "puppeted" by Sessions via the Player account. From this separation an account system follows naturally. Evennia also offers fully flexible … -
OSCON 2014 & REST API Client Best Practices
Mark Lavin, Caktus Technical Director and author of the forthcoming LightWeight Django was recently at OSCON 2014 in Portland where he gave a talk on improving the relationship between server and client for REST APIs. OSCON, with over 3000 attendees, is one of the largest open source conferences around. I sat down with him to ask him about his time there. -
OSCON 2014 & REST API Client Best Practices
Mark Lavin, Caktus Technical Director and author of the forthcoming Django LightWeight was recently at OSCON 2014 in Portland where he gave a talk on improving the relationship between server and client for REST APIs. OSCON, with over 3000 attendees, is one of the largest open source conferences around. I sat down with him to ask him about his time there. Welcome back! This was your second year speaking at OSCON. How did you enjoy it this year? I enjoyed it. There’s a variety of topics at OSCON. It’s cool to see what people do with open source—there’s such a large number of companies, technologies, and approaches to solutions. There were great conversations and presentations. I especially liked Ignite OSCON where people gave really well-prepared 5 minute talks. I participated in the OSCON 5k [Mark received 5th place] too. There were a lot of people out. We went over bridges and went up and down this spiral bridge twice. That race was pretty late for me but fun [began at 9pm PST, which is 12AM EST]. Why did you choose REST API client best practices as a talk topic? It was something that came out of working on Django LightWeight. … -
Django Extensions 1.3.9
We are happy to release: Django-Extensions Version 1.3.9 This brings the usual tons of fixes and improvements Get it at: https://pypi.python.org/pypi/django-extensions/1.3.9 Changes: Feature: shell_plus, add --kernel option to start as standalone IPython kernel Feature: reset_db, Programatically determine PostGIS template Feature: sqldiff, add support for PointField and MultiPolygonField Test: renamed test app Fix: runserver_plus, --print-sql for Django 1.7 Fix: shell_plus, --print-sql for Django 1.7 Fix: show_urls, add support for functions that use functools.partial Fix: show_urls, add formatter for aligned output (will most likely become future default) Fix: shell_plus / notebook, support for Django 1.7 Docs: various fixes and improvements Cleanup: Remove work arounds for Django 0.96 and earlier -
如何利用 Powershell 同步本機磁碟與 Amazon S3 的檔案
转自: http://blog.miniasp.com/post/2014/07/21/Sync-folders-using-S3-Explorer-PowerShell-Snap-in.aspx 最近在協助客戶將 Amazon S3 上面的檔案遷移到 Windows Azure Storage,若要遷移這些存在 S3 上面的檔案,勢必要先把檔案下載回來,所以我今天打算分享一個不用錢的解決方案,讓你可以快速的同步本機與雲端上的檔案,你可以把本機磁碟中的檔案同步到 Amazon S3,也可以從 Amazon S3 同步檔案到本機磁碟中,已經同步過的檔案還會自動跳過,所以除了第一次同步外,日後每次同步檔案的速度都將非常快。 安裝 CloudBerry Explorer for Amazon S3 或 CloudBerry Explorer for Amazon S3 PRO 由於安裝了 CloudBerry Explorer for Amazon S3 之後,會連帶自動安裝 Powershell 的 CloudBerryLab.Explorer.PSSnapIn 管理單元,在這個管理單元中包含了一組可管理 Amazon S3 的 cmdlet 命令。 不過,有點要特別注意,CloudBerryLab.Explorer.PSSnapIn 僅支援 64 位元架構下,請記得要啟動 64-bit 的 Powershell 視窗,否則會無法在執行環境中加入這個 CloudBerryLab.Explorer.PSSnapIn 管理單元。我光是這點問題,卡了我好些時間,原因就在於我的電腦有安裝 Windows Azure PowerShell 套件,所以通常我如果要透過 PowerShell 管理 Windows Azure 資源的時候,都會透過這個捷徑啟動程式: 誰知道,原來這個捷徑指向的是 32-bit 的 PowerShell 環境! 請看看這個捷徑的內容,你會看到 SysWOW64 字樣,這就代表 PowerShell 是執行在 32-bit 環境下的。 如上圖目標的內容如下: C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -File "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1" 我做了些小調整,把 powershell.exe 的路徑改一下而已,如下指令碼: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoExit -ExecutionPolicy Bypass -File "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\ServiceManagement\Azure\Services\ShortcutStartup.ps1" 使用 CloudBerryLab.Explorer.PSSnapIn 管理單元提供的命令 大致上的使用情境如下: 1. 加入 CloudBerryLab.Explorer.PSSnapIn 到當前的 PowerShell 執行環境中 (必要動作) Add-PSSnapin CloudBerryLab.Explorer.PSSnapIn 2. 列出所有 CloudBerryLab.Explorer.PSSnapIn 支援的命令 Get-Command | Where-Object {$_.PSSnapin.Name -eq "CloudBerryLab.Explorer.PSSnapIn"} 3. 先取得 S3 連線物件 $key = "YOUR_KEY" $secret = "YOUR_SECRET" $s3 = Get-CloudS3Connection -Key $key -Secret $secret -UseSSL 4. 設定要同步兩端檔案的來源與目的物件 設定來源物件 (假設我要從本機磁碟把某個目錄同步到 S3,可以用以下語法指定一個本機磁碟機) $src = Get-CloudFilesystemConnection | Select-CloudFolder "G:\TEMP" 設定目的物件 (假設我要從本機磁碟把某個目錄同步到 S3,可以用以下語法指定一個 Bucket 路徑) $dest = $s3 | Select-CloudFolder -path "your_bucket_name/vPath" 5. 將來源複製到目的 ( 這是直接從 $src 複製所有檔案到 $dest 喔,預設 Storage Class 為 STANDARD ) $src | Copy-CloudItem $dest -filter * 如果要指定複製上去的檔案預設的 Storage Class 為 RRS 的話,可以改用以下指令: $src | Copy-CloudItem $dest -filter * -StorageClass rrs 注意:使用 Copy-CloudItem 來複製檔案,並不會檢查檔案是否上傳過,所以僅適合用在第一次上傳或下載檔案的時候。 6. … -
如何利用 AzCopy 同步本機磁碟與 Azure Blob Storage 檔案
转自: http://blog.miniasp.com/post/2014/07/23/AzCopy-sync-local-disk-and-azure-blob-storage-files.aspx 最近在協助客戶將 Amazon S3 上面的檔案遷移到 Windows Azure Storage (Blob),在我的前一篇文章已經提到如何便利的從 Amazon S3 同步到本機磁碟,今天我將分享如何透過微軟提供的免費工具 AzCopy 幫我們快速達成上傳、下載、同步等工作,也是一套兼具方便性與效能的檔案同步工具,同步檔案時,他一樣不會傳輸那些已經同步過且無異動的檔案,讓我們一起來看看如何使用吧! 當你安裝過 Windows Azure SDK 或命令列工具支援,就可以在程式集中找到 Windows Azure Storage command line 捷徑,透過這個捷徑可以開啟一個能讓你執行 AzCopy 指令的命令提示字元視窗。 你可以利用 where azcopy 命令找到該執行檔所在實際位置,執行 azcopy /? 可以看到完整使用說明: 找到 AzCopy 執行檔之後,使用方式真的是簡單到不能再簡單,一個最基本的用法,就是直接指定來源與目的即可自動完成檔案同步工作。以下幾個使用情境與相對應的指令供各位參考: 1. 將本地資料夾所有檔案(含子目錄)全部上傳到Azure Blob Storage,而且會判斷不要同步比 Azure Blob Storage 來舊的檔案,也就是如果 Azure Blob Storage 檔案有更新過時,不會複製檔案上去。 AzCopy G:\TEMP https://YOUR_URL/CONTAINER/vPath /DestKey:KEY /S /XO /Z 上述指令,藍字部份都是你要修改的,而 /DestKey 代表的是你目的端的 Storage Account 的存取金鑰。 /S 代表複製所有指定目錄與其所有子目錄的所有檔案 /XO 代表當你從來源複製到目的時,排除那些比目的端舊的檔案 ( Exclude Older ) /Z 讓你本次的同步工作進入所謂 Restartable mode,他會記錄同步檔案的過程,並寫入一個 AzCopy.log 暫存檔案中,當你同步過程發生網路問題,下次執行相同的指令會自動在上次執行到一半的地方開始同步檔案! 2. 將 Azure Blob Stroage 上面的檔案全部下載回來 以下指令跟上述指令的差別,僅把來源與目的交換,然後把 /DestKey 換成 /SourceKey 而已。 AzCopy https://YOUR_URL/CONTAINER/vPath G:\TEMP /SourceKey:KEY /S /XO /Z 3. 利用 AzCopy 在兩個不同的 Storage 儲存帳戶搬移檔案 這部分基本上還算簡單,就是你的來源與目的都是 BLOB_URL 而已,但有些額外的參數可以了解,詳細資訊可參考 AzCopy – Using Cross Account Copy Blob 這篇文章。 -
在 Raspberry Pi 上安裝 mongodb
編繹安装的話,要很久,所以找到了一個 binary zip 來安裝。解開 zip 後,要用 root 執行下面這些指令,然後,就可以用了。 adduser --firstuid 100 --ingroup nogroup --shell /etc/false --disabled-password --gecos "" --no-create-home mongodb cp -R mongodb-rpi/mongo /opt chmod +x /opt/mongo/bin/* mkdir /var/log/mongodb chown mongodb:nogroup /var/log/mongodb mkdir /var/lib/mongodb chown mongodb:nogroup /var/lib/mongodb cp mongodb-rpi/debian/init.d /etc/init.d/mongod cp mongodb-rpi/debian/mongodb.conf /etc/ ln -s /opt/mongo/bin/mongod /usr/bin/mongod chmod u+x /etc/init.d/mongod update-rc.d mongod defaults /etc/init.d/mongod start -
移动应用被苹果官方推荐的秘密
转自: http://www.williamlong.info/archives/3927.html 对于中小应用开发团队来说,技术已经不是再是瓶颈,最困难的部分是如何让大家知道自己。如果应用能被苹果官方推荐,那么就会产生巨大的收益,瞬间积累几十万用户不在话下,可以说是最具效果和性价比的推广方式。作为一个仅有一年多app开发经验的团队,我们两款产品均被苹果推荐,在业界很少见,很多朋友问我如何做到的,被问得多了,我觉得有责任和义务写一篇文章,来分享下我所知道的如何获得苹果推荐。 首先说一下我们两款产品被推荐的过程(非常平淡,慎入) 2012年在我们提交第一个产品后,收到了一封来自@apple.com的邮件,邮件的内容是苹果觉得我们的产品很有意思,想要进行推荐,需要我们提供一系列的宣传素材(主要是页首海报)和产品计划表。作为刚开始做app还在跑线下宣传的屌丝,根本不知道被推荐的意义,所以虽然认真准备并提交了,但并没有抱很大期望。没想到后来真的推荐了! 然后服务器真的爆了!我们这才明白这个推荐的价值,而且一旦被推荐后会进入一个推荐候选的名单,苹果会持续的进行推荐。在这个过程中,我们与当初联系我们的联络人一直保持着联系,update我们的进展,且对遇到的问题进行反馈,邮件发了好几个月,但一直没有见面,(要见一面非常非常难)后来,几经波折,终于见到了传说中的帅哥@apple.com.本来想好要拉拉关系,扯扯家常,后来发现对方真的是非常认真的人,见了面一直在谈工作和对我们产品的建议,解释问题。再后来到第二个产品的时候,我们也主动发我们的产品资料给他,并根据他的反馈进行了一些改进,最终获得了推荐,由于之前的经验,这次服务器没有爆。:) 苹果团队的工作人员一直非常nice,整个过程也顺利得让我们想感谢老天爷。事后我们对苹果推荐产品的标准做了一些总结,要知道帅哥联络人的表情很和蔼,内心要求可是很高的,以下就是我们总结的苹果的六个“秘密”心理: 秘密一,别想拿钱套近乎。有人听到我们的应用上榜了,第一反应是问我们花了多少钱?面对这种问题,我们只能感叹要是能花钱我们肯定也花不起这个钱,当初到处去贴小广告就是因为没有预算做更好的推广啊!后来我们才知道,苹果商店的编辑团队是真正的高富帅,根本不差土豪产品的那些钱,他们要找真正优秀的产品,所以千万别指望用钱套近乎。为了实现公平公正的原则,苹果商店创建了非常合理的组织结构。全球分为几十个商店,每个商店都有自己的编辑团队,而编辑团队类似一个黑盒子,一般是接触不到的,有点像黑衣人的感觉,苹果给了这些编辑绝对的自由可以选择自己喜欢的应用。但是我们可以通过一层关系找到这些编辑,就是之前提到的联络人,官方职位叫开发者关系,他们像是连接编辑和开发者的桥梁。 秘密二,不是最新的我不要。既然说到优秀的产品,就不得不提这优秀的第一个标准,那就是概念一定要新鲜。这个其实没什么好说的,二十一世纪最贵的就是创意,不管是商业模式还是产品本身的创意可能都能起到决定性的作用。我们第一款产品上榜的时候,市场上并没有类似的应用;这款应用上线的时候,模式已经不新鲜了,但是我们可以自信地说产品里漂亮的界面、清新的画风和大量的素材还是独一无二的。 秘密三,你能为手机用户带来什么?苹果在商店首页做推荐,千万不要幼稚地以为是发善心帮你推广产品,人家的首要任务是为了推广自己的商店,所以你的产品要能给用户带来好的体验,能够实实在在地帮苹果商店留住用户,获得好评。我每周都关注苹果商店推荐,发现工具、效率和运动类的应用每期都会获得推荐,且上榜量远远大于游戏,我想这就是苹果的理念在起作用,他们推荐的应用,其目标是为了让人们的生活更丰富多彩、更高效、更健康,总的来说就是让人们生活的更美好。被推荐的都是为了让人们更好的去创造,这是非常重要的一点。 秘密四,请体现苹果的气质。如果前面大家觉得我说的都在扯淡,那可以从这里开始请认真看,我要开始认真的说了。关于设计,其重要性应该已经形成共识,但是,既然我们在谈如何被苹果推荐,那么这里说的设计风格主要指的是苹果的风格。尤其重要的是,苹果非常喜欢能够跟得上他们的系统迭代的产品。记得IOS7刚出来的时候,他们专门推了一个IOS7风格应用的推荐主题,这是最明显的引导。从Icon设计到内部界面都应该认真对待,试想如果没有达到苹果的水平或者风格差异过大,应用放在App Store上是有损苹果的形象的。 秘密五,最喜欢surprise了。这一点实际是高质量的延伸,高大上的团队一般也喜欢高大上的应用。针对如何让应用显得高大上这个问题,我能给出的建议就是在细节处给用户或者编辑惊喜。一个漂亮的提示,精彩的跳转动画,搞笑的小动画和充满创意的loading都会让你的应用显得与众不同,甚至可以说是区别高质量应用和低质量应用的关键区别。 秘密六,世界的才是最好的。我们当时为产品做了一个英文版本,没想到正中苹果下怀。苹果倾向有多语言版本的应用,因为开发者关系在看到一个感兴趣的应用时,会向多个市场进行推荐,因此有多语言版本的应用,有更大机会获得推荐,这一条的操作请自觉配合前面五条,因为只有在做到前面五点的前提下,多语言版本才显得有意义,算一个加分项。 总的来说,做应用还是要做自己爱的应用,并且将自己的灵魂融入其中,这样才可能做出令人印象深刻的产品,也能让app脱颖而出。面对几百万的开发者,如何脱颖而出,已经不仅仅是一项技术活,而是专注、热情、韧性、天赋和运气的综合比拼。苹果商店是一个公平的舞台,这里只是分享下我的经历和小技巧,文章写的有点乱,最开始以为在写推广,后来发现在写产品。好吧,我承认这是有意而为(才怪),我认为最好的推广是把产品做好,所有资源就自动地会向你靠拢,如果为了迎合渠道而去做产品,可能会忘了初心,迷失方向,你说呢? -
pyRserve: 连接远程 R 语言进程的 Python 客户端
pyRserve是一个纯pyhton的客户端, 用于连接远程的R进程. R是现在开源界最重要和最广为使用的统计语言. 通过pyRserve连接R进程, 可以在python中最大的利用R语言. pyRserve的安装不需要其他依赖包, 子需要使用pip安装即可. 简单的使用代码如下: >>> import pyRserve >>> conn = pyRserve.connect('Rserve.example.com') >>> conn.eval('sum( c(1.5, 4) )') # 直接在R中执行语句 >>> conn.r.myList = [1, 2, 3] # 将python list连接到R中的变量mylist >>> conn.voidEval('func1 >> conn.r.func1(4) # 在R中运行function 16 更多的信息可以查看其文档: https://pythonhosted.org/pyRserve/ -
Want to work for Eventbrite? (part 2)
For various reasons I had to change some things about my Eventbrite test. The new version is listed here and the previous blog post has been updated: 104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 115, 116, 46, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 112, 121, 100, 97, 110, 110, 121, 47, 97, 56, 55, 100, 57, 54, 49, 54, 102, 49, 50, 55, 52, 48, 48, 97, 57, 55, 97, 52 Good luck! -
Want to work for Eventbrite? (part 2)
For various reasons I had to change some things about my Eventbrite test. The new version is listed here and the previous blog post has been updated: 104, 116, 116, 112, 115, 58, 47, 47, 103, 105, 115, 116, 46, 103, 105, 116, 104, 117, 98, 46, 99, 111, 109, 47, 112, 121, 100, 97, 110, 110, 121, 47, 97, 56, 55, 100, 57, 54, 49, 54, 102, 49, 50, 55, 52, 48, 48, 97, 57, 55, 97, 52 Good luck! -
Want to work for Eventbrite?
Join me, Andrew Godwin (South, Django migrations), Simon Willison (co-founder of Django, co-founder of Lanyrd), and many other talented people at Eventbrite. We have great challenges, the kind that inspire you to rise to the occasion. We need you to help us overcome them. I should mention that Eventbrite is committed to giving back to the community. Most notably Eventbrite just contributed £5000 to the Django Rest Framework kickstarter, or about US$8500!! We're a frequent sponsor of events around the world. It doesn't stop there, as Eventbrite managers during the discussion of any tool outside our domain of running events will ask: "When can we open source this?" As someone who loves working on open source, Eventbrite is the place to be. I say this because I know what we're planning to do in the future. If you join us, you'll find out sooner rather than later. ;) What's Eventbrite like as a company? Well, we're rated in the top 20 of best places to work in the United States. We get full benefits, free lunch, educational opportunities, and much more. In addition, I have to say that my co-workers are friendly, intelligent, always learning, and love to do things … -
Want to work for Eventbrite?
Join me, Andrew Godwin (South, Django migrations), Simon Willison (co-founder of Django, co-founder of Lanyrd), and many other talented people at Eventbrite. We have great challenges, the kind that inspire you to rise to the occasion. We need you to help us overcome them. I should mention that Eventbrite is committed to giving back to the community. Most notably Eventbrite just contributed £5000 to the Django Rest Framework kickstarter, or about US$8500!!. We're a frequent sponsor of events around the world. It doesn't stop there, as Eventbrite managers during the discussion of any tool outside our domain of running events will ask: "When can we open source this?" As someone who loves working on open source, Eventbrite is the place to be. I say this because I know what we're planning to do in the future. If you join us, you'll find out sooner rather than later. ;) What's Eventbrite like as a company? Well, we're rated in the top 20 of best places to work in the United States. We get full benefits, free lunch, educational opportunities, and much more. In addition, I have to say that my co-workers are friendly, intelligent, always learning, and love to do things … -
网站压力测试工具
转自: http://www.yeolar.com/note/2012/11/24/web-bench-test/ 网站压力测试就是测试网站能够承受多大的访问量,以及在大访问量的情况下网站的性能。这些指标会直接影响用户的体验,因此在网站上线前一般都要做压力测试。压力测试也是考察网站使用的相关web服务器和框架的一个重要手段。 因为和真实的环境不同,压力测试通过模拟得到的结果不会和实际的负载完全相同,但它仍是一个很好的基准比较。做压力测试时也会尽可能地模拟实际的情况。 网上大家推荐的较为常见的网站压力测试工具有ab、webbench、http_load、siege、curl-loader、multi-mechanize、tcpcopy等。 这里的大部分测试工具采用事件驱动模型来创建模拟用户,比如ab使用 apr 包中的 apr_pollset_poll 函数,而其他的工具都使用 select 函数,只有webbench通过 fork 子进程来创建模拟用户,它能模拟的并发数更高。 我把大家的一些总结列在这里: ab Apache自带的压力测试工具,还有一个 独立版本 。主要用于测试网站的每秒处理请求数,多用于静态压力测试。基本用法是: $ ab -n 1000 -c 50 http://192.168.1.101/ -n 总请求数 -c 并发连接数 输出的结果如下: Server Software: Apache/2.2.16 Server Hostname: 192.168.1.101 Server Port: 80 Document Path: / 请求文档路径 Document Length: 14643 bytes 请求文档大小 Concurrency Level: 50 并发数 Time taken for tests: 38.724 seconds 总测试时间 Complete requests: 1000 全部请求数 Failed requests: 14 失败请求数 (Connect: 0, Receive: 0, Length: 14, Exceptions: 0) Write errors: 14 Total transferred: 14847500 bytes 总数据传输量 HTML transferred: 14548500 bytes HTML数据传输量 Requests per second: 25.82 [#/sec] (mean) 平均每秒请求数 Time per request: 1936.210 [ms] (mean) 平均每次并发所有请求时间 Time per request: 38.724 [ms] (mean, across all concurrent requests) 平均每次请求时间 Transfer rate: 374.43 [Kbytes/sec] received 传输速率 Connection Times (ms) min mean[+/-sd] median max Connect: 2 668 1905.0 135 12237 连接时间 Processing: 0 1244 1652.3 902 14963 处理时间 Waiting: 0 1222 1651.1 883 14955 等待时间 Total: 134 1912 2723.5 1126 15096 Percentage of the requests served within a certain time (ms) 50% 1126 66% 1321 75% 1369 80% 1408 90% 1917 95% 10122 98% 13030 99% 13884 100% 15096 (longest request) webbench 它主要测试每秒请求数,同时支持静态、动态和SSL,单例最多可模拟3万并发,适合小型网站的压力测试。 基本用法是: $ webbench -c 100 -t 60 http://192.168.1.101/ -c 并发数 -t 测试时间 测试结果如下: Benchmarking: … -
Django 和 PostgreSQL, 从 SQL 的 LIKE 到全文搜索(Full-Text-Search) (2)
在上一篇中, 我们解决了明确搜索的问题, 这一篇中我们说说口音或相近语的问题. 在使用全文搜索是我们会发现, 使用多种语言搜索document是常有的事情. 我们可以不设置语言而是用to_tsquery, 但是在运行的过程中, 全文搜素总是会自动使用至少一个. 默认的语言设置时英语, 但你必须根据你document的语言使用正确的stemmer, 否则就无法找到匹配. 例如, 我们在西班牙语的document中搜索física, 能得到精确地匹配: => SELECT text FROM terms WHERE to_tsvector(text) @@ to_tsquery('física'); text ------------------------------------------------------------------------- física (aparatos e instrumentos de —) física (educación —) física (investigación en —) rehabilitación física (aparatos de —) para uso médico educación física conversión de datos y programas informáticos, excepto conversión física investigación en física terapia física (8 rows) 但如果搜索fisica, 不带口音设置, 则无法得到任何结果: => SELECT text FROM terms WHERE to_tsvector(text) @@ to_tsquery('fisica'); text ------ (0 rows) 为了能在结果中显示física和其变体(físicas, físico, físicamente, 等), 我们必须使用正确的stemmer. 如果stemmer中没有这个词, 那么我们也无法获得正确的结果: => SELECT ts_lexize('english_stem', 'programming'); ts_lexize ----------- {program} (1 row) => SELECT ts_lexize('spanish_stem', 'programming'); ts_lexize --------------- {programming} (1 row) 但当使用正确的语言设置时: => SELECT text FROM terms WHERE to_tsvector('spanish', text) @@ to_tsquery('spanish', 'física'); text -------------------------------------------------------------------------------- física (aparatos e instrumentos de —) ejercicios físicos (aparatos para —) entrenamiento físico (aparatos de —) físicos (aparatos para ejercicios —) física (educación —) preparador físico personal [mantenimiento físico] (servicios de —) física (investigación en —) ejercicio físico (aparatos de —) para uso médico rehabilitación física (aparatos de —) para uso médico aparatos para ejercicios físicos almacenamiento de soportes físicos de datos o documentos electrónicos clases de mantenimiento físico clubes deportivos [entrenamiento y mantenimiento físico] educación física conversión de datos o … -
Contributing Back to Symposion
Recently Caktus collaborated with the organizers of PyOhio, a free regional Python conference, to launch the PyOhio 2014 conference website. The conference starts this weekend, July 26 - 27. As in prior years, the conference web site utilizes Eldarion’s Symposion, an opensource conference management system. Symposion powers a number of annual conference sites including PyCon and DjangoCon. In fact, as of this writing, there are 78 forks of Symposion, a nod to its widespread use for events both large and small. This collaboration afforded us the opportunity to abide by one our core tenets, that of giving back to the community. PyOhio organizers had identified a few pain points during last year’s rollout that were resolvable in a manner that was conducive to contributing back to Symposion so that future adopters could benefit from this work. The areas we focused on were migration support, refining the user experience for proposal submitters and sponsor applicants, and schedule building. Migration Support https://github.com/pinax/symposion/pull/47 The majority of our projects utilize South for tracking database migrations. They are not an absolute requirement but for those conferences that reused the same code base from year to year, rather than starting a new repository, it would be … -
Contributing Back to Symposion
Recently Caktus collaborated with the organizers of PyOhio, a free regional Python conference, to launch the PyOhio 2014 conference website. The conference starts this weekend, July 26 - 27. As in prior years, the conference web site utilizes Eldarion’s Symposion, an opensource conference management system. Symposion powers a number of annual conference sites including PyCon and DjangoCon. In fact, as of this writing, there are 78 forks of Symposion, a nod to its widespread use for events both large and small. This collaboration afforded us the opportunity to abide by one our core tenets, that of giving back to the community. -
TCP 的那些事儿(下)
上篇中,我们介绍了TCP的协议头、状态机、数据重传中的东西。但是TCP要解决一个很大的事,那就是要在一个网络根据不同的情况来动态调整自己的发包的速度,小则让自己的连接更稳定,大则让整个网络更稳定。在你阅读下篇之前,你需要做好准备,本篇文章有好些算法和策略,可能会引发你的各种思考,让你的大脑分配很多内存和计算资源,所以,不适合在厕所中阅读。 TCP的RTT算法p TCP的RTT算法 设长了,重发就慢,丢了老半天才重发,没有效率,性能差; 设短了,会导致可能并没有丢就重发。于是重发的就快,会增加网络拥塞,导致更多的超时,更多的超时导致更多的重发。 而且,这个超时时间在不同的网络的情况下,根本没有办法设置一个死的值。只能动态地设置。 为了动态地设置,TCP引入了RTT——Round Trip Time,也就是一个数据包从发出去到回来的时间。这样发送端就大约知道需要多少的时间,从而可以方便地设置Timeout——RTO(Retransmission TimeOut),以让我们的重传机制更高效。 听起来似乎很简单,好像就是在发送端发包时记下t0,然后接收端再把这个ack回来时再记一个t1,于是RTT = t1 – t0。没那么简单,这只是一个采样,不能代表普遍情况。 经典算法 RFC793 中定义的经典算法是这样的: 首先,先采样RTT,记下最近好几次的RTT值。 然后做平滑计算SRTT( Smoothed RTT)。公式为:(其中的 α 取值在0.8 到 0.9之间,这个算法英文叫Exponential weighted moving average,中文叫:加权移动平均) SRTT = ( α * SRTT ) + ((1- α) * RTT) 开始计算RTO。公式如下:RTO = min [ UBOUND, max [ LBOUND, (β * SRTT) ] ] 其中: UBOUND是最大的timeout时间,上限值 LBOUND是最小的timeout时间,下限值 β 值一般在1.3到2.0之间。 Karn / Partridge 算法 但是上面的这个算法在重传的时候会出有一个终极问题——你是用第一次发数据的时间和ack回来的时间做RTT样本值,还是用重传的时间和ACK回来的时间做RTT样本值? 这个问题无论你选那头都是按下葫芦起了瓢。 如下图所示: 情况(a)是ack没回来,所以重传。如果你计算第一次发送和ACK的时间,那么,明显算大了。 情况(b)是ack回来慢了,但是导致了重传,但刚重传不一会儿,之前ACK就回来了。如果你是算重传的时间和ACK回来的时间的差,就会算短了。 所以1987年的时候,搞了一个叫Karn / Partridge Algorithm,这个算法的最大特点是——忽略重传,不把重传的RTT做采样(你看,你不需要去解决不存在的问题)。 但是,这样一来,又会引发一个大BUG——如果在某一时间,网络闪动,突然变慢了,产生了比较大的延时,这个延时导致要重转所有的包(因为之前的RTO很小),于是,因为重转的不算,所以,RTO就不会被更新,这是一个灾难。 于是Karn算法用了一个取巧的方式——只要一发生重传,就对现有的RTO值翻倍(这就是所谓的 Exponential backoff),很明显,这种死规矩对于一个需要估计比较准确的RTT也不靠谱。 Jacobson / Karels 算法 前面两种算法用的都是“加权移动平均”,这种方法最大的毛病就是如果RTT有一个大的波动的话,很难被发现,因为被平滑掉了。所以,1988年,又有人推出来了一个新的算法,这个算法叫Jacobson / Karels Algorithm(参看RFC6289)。这个算法引入了最新的RTT的采样和平滑过的SRTT的差距做因子来计算。 公式如下:(其中的DevRTT是Deviation RTT的意思) SRTT = SRTT + α (RTT – SRTT) —— 计算平滑RTT DevRTT = (1-β)*DevRTT + β*(|RTT-SRTT|) ——计算平滑RTT和真实的差距(加权移动平均) RTO= µ * SRTT + ∂ *DevRTT —— 神一样的公式 (其中:在Linux下,α = 0.125,β = 0.25, μ = 1,∂ = 4 ——这就是算法中的“调得一手好参数”,nobody knows why, it just works…) 最后的这个算法在被用在今天的TCP协议中(Linux的源代码在:tcp_rtt_estimator) TCP滑动窗口 需要说明一下,如果你不了解TCP的滑动窗口这个事,你等于不了解TCP协议。我们都知道,TCP必需要解决的可靠传输以及包乱序(reordering)的问题,所以,TCP必需要知道网络实际的数据处理带宽或是数据处理速度,这样才不会引起网络拥塞,导致丢包。 所以,TCP引入了一些技术和设计来做网络流控,Sliding Window是其中一个技术。 前面我们说过,TCP头里有一个字段叫Window,又叫Advertised-Window,这个字段是接收端告诉发送端自己还有多少缓冲区可以接收数据。于是发送端就可以根据这个接收端的处理能力来发送数据,而不会导致接收端处理不过来。 为了说明滑动窗口,我们需要先看一下TCP缓冲区的一些数据结构: 上图中,我们可以看到: 接收端LastByteRead指向了TCP缓冲区中读到的位置,NextByteExpected指向的地方是收到的连续包的最后一个位置,LastByteRcved指向的是收到的包的最后一个位置,我们可以看到中间有些数据还没有到达,所以有数据空白区。 发送端的LastByteAcked指向了被接收端Ack过的位置(表示成功发送确认),LastByteSent表示发出去了,但还没有收到成功确认的Ack,LastByteWritten指向的是上层应用正在写的地方。 于是: 接收端在给发送端回ACK中会汇报自己的AdvertisedWindow = MaxRcvBuffer – LastByteRcvd – 1; 而发送方会根据这个窗口来控制发送数据的大小,以保证接收方可以处理。 下面我们来看一下发送方的滑动窗口示意图: 上图中分成了四个部分,分别是:(其中那个黑模型就是滑动窗口) #1已收到ack确认的数据。 #2发还没收到ack的。 #3在窗口中还没有发出的(接收方还有空间)。 #4窗口以外的数据(接收方没空间) 下面是个滑动后的示意图(收到36的ack,并发出了46-51的字节): 下面我们来看一个接受端控制发送端的图示: Zero Window 上图,我们可以看到一个处理缓慢的Server(接收端)是怎么把Client(发送端)的TCP Sliding Window给降成0的。此时,你一定会问,如果Window变成0了,TCP会怎么样?是不是发送端就不发数据了?是的,发送端就不发数据了,你可以想像成“Window Closed”,那你一定还会问,如果发送端不发数据了,接收方一会儿Window size 可用了,怎么通知发送端呢? 解决这个问题,TCP使用了Zero Window Probe技术,缩写为ZWP,也就是说,发送端在窗口变成0后,会发ZWP的包给接收方,让接收方来ack他的Window尺寸,一般这个值会设置成3次,第次大约30-60秒(不同的实现可能会不一样)。如果3次过后还是0的话,有的TCP实现就会发RST把链接断了。 注意:只要有等待的地方都可能出现DDoS攻击,Zero Window也不例外,一些攻击者会在和HTTP建好链发完GET请求后,就把Window设置为0,然后服务端就只能等待进行ZWP,于是攻击者会并发大量的这样的请求,把服务器端的资源耗尽。(关于这方面的攻击,大家可以移步看一下Wikipedia的SockStress词条) 另外,Wireshark中,你可以使用tcp.analysis.zero_window来过滤包,然后使用右键菜单里的follow TCP stream,你可以看到ZeroWindowProbe及ZeroWindowProbeAck的包。 Silly Window Syndrome Silly Window Syndrome翻译成中文就是“糊涂窗口综合症”。正如你上面看到的一样,如果我们的接收方太忙了,来不及取走Receive Windows里的数据,那么,就会导致发送方越来越小。到最后,如果接收方腾出几个字节并告诉发送方现在有几个字节的window,而我们的发送方会义无反顾地发送这几个字节。 要知道,我们的TCP+IP头有40个字节,为了几个字节,要达上这么大的开销,这太不经济了。 另外,你需要知道网络上有个MTU,对于以太网来说,MTU是1500字节,除去TCP+IP头的40个字节,真正的数据传输可以有1460,这就是所谓的MSS(Max Segment Size)注意,TCP的RFC定义这个MSS的默认值是536,这是因为 RFC 791里说了任何一个IP设备都得最少接收576尺寸的大小(实际上来说576是拨号的网络的MTU,而576减去IP头的20个字节就是536)。 如果你的网络包可以塞满MTU,那么你可以用满整个带宽,如果不能,那么你就会浪费带宽。(大于MTU的包有两种结局,一种是直接被丢了,另一种是会被重新分块打包发送) 你可以想像成一个MTU就相当于一个飞机的最多可以装的人,如果这飞机里满载的话,带宽最高,如果一个飞机只运一个人的话,无疑成本增加了,也而相当二。 所以,Silly Windows Syndrome这个现像就像是你本来可以坐200人的飞机里只做了一两个人。 要解决这个问题也不难,就是避免对小的window size做出响应,直到有足够大的window size再响应,这个思路可以同时实现在sender和receiver两端。 如果这个问题是由Receiver端引起的,那么就会使用 David D Clark’s 方案。在receiver端,如果收到的数据导致window size小于某个值,可以直接ack(0)回sender,这样就把window给关闭了,也阻止了sender再发数据过来,等到receiver端处理了一些数据后windows size 大于等于了MSS,或者,receiver buffer有一半为空,就可以把window打开让send …