portrait

mudkip.me

Mudkip is a Pokémon enthusiast, a web and iOS developer, a geek and an otaku who never grows up.

How In-app Purchases Have Destroyed The Industry ∞

It’s a tragedy that there’s no solution to this. But we consumers should support games with good principle and stay away from craps with dirty minds.

I removed Real Racing 3 and Plants vs Zombies 2 from my iOS devices after reading this article. They are good games, but I realize as a player I have a responsibility to boycott against their business model.

IAPs aren’t always this bad. I buy IAPs or DLCs from games like Pokémon Mystery Dungeon Gates to Infinity, Ace Attorney Trilogy HD, Ghost Trick for iOS, and New Super Mario Bros 2. They use free-to-play as a trial or IAPs as bonus contents to games, and we know when we pay enough.

Feb 4, 2014

My iOS Setup 2013 Version

iOS devices became an essential part of my life since I purchased a 4th generation iPod touch in 2010. Currently I have an iPhone 5s, a 1st gen iPad mini with 3G, and an iPad Air. They are incredible devices I rely on all the time.

This is a list of apps I was using by the end of 2013. Many of them work on both iPhone and iPad, some are better together and sync with a Mac equivalent to the cloud.

Reading & Social Networking

  • Tweetbot: Checking Twitter is the first thing I do every morning. Tweetbot is a fantastic client and my most-used app on my iPhone. I like background update, the clean interface, and the subtle animations of Tweetbot 3 and I wish the iPad version could be updated for iOS 7 soon.
  • Reeder 2: Reeder is my favorite RSS client. The delighted design and powerful sharing feature of Reeder make it my favorite RSS client on both iPhone and iPad. I also use Sunstroke in addition as it suits Fever better.
  • Instapaper: Instapaper is the best read later service. After Instapaper was purchased by betaworks, it was updated with many interesting features like InstaRank, background sync and an iOS 7 interface. Sometimes I also use Pocket or Safari’s Reading List. I always feel guilty for the bottomless unread lists.
  • PDF Expert: PDF Expert is by far the best PDF reading and annotating app on the iPad. It’s also a great file organizer and a client of many cloud services. I use Documents on my iPhone and it syncs via iCloud with PDF Expert as they’re created by the same developer.
  • iBooks: I really love reading books in .iBooks format, among which CSS Transforms: An Interactive Guide is awesome. I keep dozens of ePub books in iBooks but I read them on my Kindle Paperwhite (in .mobi format) mostly.
  • Kindle: The iOS 7 update of Kindle app is fairly nice, especially when reading thick programming books. Since I buy books from both US and China’s Kindle store, being unable to use two accounts with one device was annoying but I found a workaround by stripping out the DRM.
  • Tumblr: I use the official Tumblr to browse interesting Tumblogs I follow. While this blog is hosted on Tumblr, when I write something, I use Byword instead.
  • Zite & Flipboard: Zite is my news aggregator and I read Flipboard for personal magazines.
  • Baidu Zhidao: The best source for answers to casual questions. Its polished design and graceful font in the latest version is impressive. Undoubtedly I love this app :)
  • Weico Pro: I check Weibo often but I never publish anything. Weico is a elegant client for it. Like many other apps, the iPad version needs iOS 7 redesign.
  • WeChat & QQ: As a Chinese netizen, there’s no doubt that my most-used IM services are provided by Tencent. Beyond direct messaging, WeChat also has interesting features like group chat, payment and public publishing.
  • Felix: I occasionally check my App.net timeline. Felix is an App.net client with interesting design, fonts and gestures. I wish the App.net community keeps growing.
  • The Magazine & The Loop Magazine: These two are the only magazines I subscribed to. Both magazine provide several long-form geek-friendly articles every two weeks. It’s an enjoyment reading them leisurely.
  • Pinbook: Pinbook is a good Pinboard client. It can sync and search pretty fast. I also like its sharing feature and URL scheme. An iOS 7 update of Pinbook is coming soon.

Writing & Note-Taking

  • Drafts: Drafts is a brilliant quick note-taking app. When I remember something to write down, or I want to transcribe the dialog when playing games, I always use Drafts. It has tons of speedy actions and connects to Dropbox, Evernote or other apps by URL schemes.
  • Simplenote: The simplest lightest plain-text note-taking app. It syncs fast. On the Mac I use nvALT.
  • Evernote: I store many things in Evernote. The iOS 7 redesign of Evernote makes researching, reading and annotating much better.
  • Byword: As I said before, I like the Markdown syntax highlighting of Byword, and I think Byword is the first app using iOS 7’s Text Kit. Byword can also publish to WordPress, Tumblr and Evernote directly.
  • Day One: Day One is my personal journal. Besides of keeping text diary beautifully, Day One can also keep photo, location data and weather. It can also record motion and step number when using an iPhone 5s.
  • Poster: Poster is a great Markdown WordPress blog poster. It was purchased and shut down by Automattic, the company of WordPress, but previous users can still get updates. I hope the features of Poster can be migrated to the official WordPress app.

Productivity

  • Things: Things is the app for getting things done. It’s easy to start with and it syncs with the cloud really fast. They announced a redesigned Things 2 is coming by the end of last year.
  • 1Password 4: 1Password is a must-have password manager. I use 1Password to store all my passwords and software licenses. I wish the Mac version can sync with both iCloud and Dropbox perfectly like the iOS version.
  • Fantastical 2: Fantastical 2 for iPhone is more than its Mac equivalent. It’s the best replacement for the built-in Calendar and Reminders app. It’s delightful to add and browse events and to-dos in Fantastical 2.
  • Launch Center Pro: Currently I only use Launch Center Pro to do simple tasks like searching 1Password, accessing articles on 52Poké Wiki, creating events and tweeting. But it’s a powerful automation app and I’m eager to research it more.
  • Clear+: Clear+ is yet another to-do list app. I like its ‘gamificated’ navigation and gestures and I wish it could sync with Reminders in the future.
  • Trello: Trello is a project organizing service which has great web and native apps. I use Trello to manage my reading, playing lists and multiple projects. As a JavaScript developer, another reason I like this service is its tech stack.
  • MindNode 3: MindNode is a beautiful app for mind mapping. The iOS 7 redesign not only has a clean and simple UI, but also new document browser, sharing, and dozens of new features.
  • Soulver: The best calculator, scratchpad and currency convertor. It’s also redesigned for iOS 7 and became a universal app syncing with iCloud.
  • OmniOutliner 2: OmniOutliner is a powerful tool to outlining my ideas. It syncs with OmniOutliner for Mac via its own OmniPresence service, which I believe is more reliable than iCloud. I wish it could have a iPhone version.
  • Focus Time: Focus Time is a simple beautiful Pomodoro app. It lets me focus on the task I’m doing, like writing this post.
  • Keynote & Numbers: The iWork apps get remakes in 2013. As a light user of both apps, I really love the new designs and iCloud sync on both iOS and Mac.

Development & Connecting to the Cloud

  • Google Drive: I use Google Drive to collaborate with my friends or share documents. The iOS app works fast and reliably. I believe it’s better than iWork’s equivalent.
  • FileBrowser: The best app to connect my Synology NAS. It can also connect multiple cloud services and protocols.
  • Prompt: A nice shell client. It has powerful yet easy to use customizable keys and key-pair support. I use it to connect my work machine, my home NAS and my Linode.
  • Linode Manager: The official Linode app received a nice upgrade last year. The buttons in it still feel dangerous. But it’s convenient to check the CPU, bandwidth and I/O of my Linode.
  • Analytiks: The most beautiful Google Analytics iPhone app. It provides informations of pageviews, demographics and social network stats.
  • Pushover: Pushover provides a very easy API to push any message to my iPhone. I use it to monitor my Linode. It also have plugins for many services like WordPress.
  • CodeHub & CodeBucket: Github and Bitbucket clients made by the same developer. I’m not a heavy Github users yet, but the app makes me easier to follow the issues I care about.
  • Diet Coda: I never do actual coding on my iPad yet. But Diet Coda is a nice app to do subtle editing or quick fixes to my Linode.

Entertainment

  • Pocket Casts: Podcasts are awesome. I was an Instacast fan before. But after iOS 7 triggered the podcast app war and dozens of podcast apps came out, I realized Pocket Casts has better layout, navigation and now playing screen.
  • Music: Music is not the only built-in app I use, but the only built-in app I want to emphasize, because of iTunes Match and Radio. iTunes Match stores all my music in the cloud in 256K iTunes Plus AAC quality. iTunes Radio is a great service to discover music.
  • nPlayer: nPlayer is the app I use to watch videos stored on my NAS. It supports many audio & video formats and many types of subtitles. I might also try Infuse 2 when it can show off the library view for streamed files.
  • Xiami: After trying many music streaming services, I found Xiami always accurately discovers the music I like to listen to. The iPhone app has nice iOS 7 design and great now playing screen. I hope the iPad version could come out soon.
  • iQiyi: iQiyi provide high quality streaming for Pokémon anime legally in China, as well as many other anime and TV series.

Utilities & Liftstyle

  • Screens 3: It lets me connect my Mac anywhere. It has clean iOS 7 interface, fast connection and many ways to control the computer. It can also connect Windows and Linux PCs.
  • Sleep Cycle: The best app to monitor my sleep quality and wake me up. It works magically every night and I like the beautiful music in it.
  • Thunderspace 2: When I put on my headphone and open this app, the rain begins to pour outside my window and the thunder crashes.
  • Baidu Map: I use Baidu Map mostly because of its vector graphics and public transmit feature. It also has many location based services like ordering taxi.
  • Skitch 3: Completely redesigned in 2013, Skitch became a fast app to shot and annotate. I use it to mark my screenshots for reporting bugs or creating guides.

Photograph

  • Camera+: It’s called the ultimate photo app. I like its easy clarify and Lightbox feature, as well as the powerful editing tools and numerous filters.
  • DS Photo+: My Synology NAS is also my private cloud photo storage service. It improved gradually over years. The interface of both the web and mobile apps became modern and beautiful in 2013.
  • Baidu Translate: No kidding, it can take a photo of any physical objects and tell me what it is. It often tells a ridiculous answer which also makes sense. But when I really need it, it answers correctly. By the way this is also a good translate/dictionary app.

2014 Wishes

Again it’s time for making wishes. Other than the satisfaction I have with my Mac, there are many things in need of improvements with my iOS setup, and I believe they’re gonna be better sooner than later in this year. The first thing is obviously iOS 7.

iOS 7 is overall the greatest update to iOS. Like many others, I love the new design and features of iOS 7. But we can’t deny its instability, especially on 64-bit A7 devices. I can see white Apple icon during multitasking interface multiple times in a week, and I even saw blue screen of death once on my iPhone 5s. On A5 devices like my iPad mini, iOS 7 is pretty slow though I don’t regret the upgrade. I wish iOS 7.1 can resolve most of these problems.

Many of my most used apps are lack of a iOS 7 redesign yet, especially on the iPad. I understand the hard work of iOS 7-friendly redesigning and coding for indie developers. I hope the outcome in this year be delightful.

I’m not a heavy user of productivity apps with automation features yet. I wish I could get more help form tools like Drafts and Launch Center Pro, as well as Editorial recommended by many writers.

Seven years ago, it’s hard to believe I was gonna have a device which has access to all the information of human 10 times faster than my then boardband network, calculates faster than most computers at that time, and even has almost the same amount of pixels of my then 17 inch screen right in my pocket. I wonder how my life will be different another seven years later.

Jan 27, 2014

My Mac Setup 2013 Version

For a long time, I enjoy trying different and high quality software. As a plan of restarting blogging, I decided to review and write about the apps I use on each platform in my life.

My whole setup changed a lot in 2013. Notably, I replaced my Late 2010 Macbook Air with a Late 2013 Retina Macbook Pro 13″. The retina display not only enables my eyes to a new resolution, but also enlightens lots of things in my web development.

This is a list of Mac apps I rely on in 2013. I’ll list my favorite iOS apps in separate posts.

Development

  • Sublime Text: I wasn’t a big fan of Sublime Text until I tried not using it for a while. It has so many powerful features I can hardly leave, as well as a splendid package manager. Sublime Text 3 also solved many little inconveniences, like it can now display images and their size like Coda.
  • iTerm 2: I spend a lot of time in terminal and this is the best app for it. I also use oh-my-zsh as my shell.
  • CodeKit: When I’m working a static project, I also need to do things like compiling Less and minifying JavaScript. CodeKit helps me do these in no time. It just works.
  • CodeRunner: As a developer it’s a joy to write small JavaScript or PHP scripts to do little things like formatting a chunk of texts. CodeRunner let me do that without choose a location to save file. It’s also a good code editor.
  • Kaleidoscope: This is the best diff tool. I haven’t used it much yet, but when I diff SVN branches with hundreds of changes, Kaleidoscope is a life saver.
  • Dash: Dash is an essential document viewer for every developer. It’s integrated well with lots of text editors and productivity tools.
  • Charles: Charles is a reverse proxy that can monitor and hack every request. I often use it to map requests to local files or fiddle with HTTP headers. I wish a more native UI in the future.
  • Sequel Pro: Sequel Pro is a free and open source MySQL/MariaDB client. It has a delightful user interface and many pro features.
  • Base: Base is just like Sequel Pro, but for SQLite.
  • Cornerstone 2: I still don’t use a GUI for SVN often. But Cornerstone has a key feature I enjoy most: I can pick any date in a giant SVN repository and quickly browse files like in Time Machine.
  • Tower: It is a powerful Git client. I haven’t learned much about git commands yet since I use SVN at work. So when I use Git, I only use Tower.

Writing and Note-taking

  • Byword: It’s a simple and beautiful writer on Mac and iOS with iCloud and Dropbox syncing. I prefer Byword mainly because of its Markdown syntax highlighting on both platforms. I’m writing this in Byword.
  • MarsEdit: MarsEdit is the best tool to publish and edit blogs of WordPress and Tumblr platform. I enjoy its preview and media features.
  • Evernote: Evernote is my universal inbox. I save long notes, web clips, PDFs and things I’d like to share in Evernote.
  • nvALT: nvALT is the best app to keep plain text notes. I like its keyboard shortcuts and sync with Simplenote on iOS devices.
  • Day One: Keeping a diary is one of my unfulfilled wish, but I keep a private weekly journal with Day One. It’s really beautiful and sync across multiple devices with iCloud and Dropbox.

Productivity

  • Alfred 2: It’s hard to describe how awesome this tool is so it’s better to just try. I use it a hundred times per day.
  • Things: Things is a simple delightful to-do list. Its cloud sync feature is blazing fast comparing to its rivals, but users in mainland China might need a little work to enable it since Things uses Google App Engine.
  • 1Password 4: It is a must-have for everyone. It’s common sense that we shouldn’t use same password on any two services. 1Password is the password manager. The newest version added many powerful features like security audit.
  • Fantastical: It’s a convenient menu bar calendar. Its natural language engine isn’t magical for non-English users, but I get used to it.
  • MindNode Pro: It is a intuitive mind mapping tool on both Mac and iOS. I love its Delight theme. Actually this list is first mind-mapped in MindNode.
  • PopClip: PopClip enables an iOS-like popup when selecting texts, but with a hundred more features.
  • Soulver: Soulver is my default calculator. It’s super smart and can convert currencies. It syncs across Macs, iPhones and iPads as well.
  • OmniOutliner 4: OmniOutliner can be used in many ways like planning projects, write long articles and spreadsheeting. I use OmniOutliner 4 beta for months and it’s just released this week. It also has a splendid iPad counterpart.
  • TextExpander 4: TextExpander is also a must-have. It allows me to type shell scripts, CSS vendor prefixes, JavaScript snippets, Markdown links and special characters in one second.

Reading & Social Networking

  • ReadKit: ReadKit is my Instapaper and RSS client. It has great smart folders and works with dozens of services.
  • Tweetbot: Tweetbot is the best Twitter client on any platform. I try to use it less as it kills productivity.

Design & Image Editing

  • Pixelmator: I use Pixelmator to do basic image editing and exporting. It’s a lot easier and prettier than Photoshop. I’d like to learn more about its feature in near future.
  • xScope: I use xScope as my ruler and eyedropper on screen.
  • ImageOptim & ImageAlpha: These are two image optimizer I use often. ImageOptim can make PNG files smaller like magic without any noticeable loss.
  • Ember: Ember is only recently landed on my Mac. I use it as a personal collection of beautiful web designs I happened to see. It syncs with iPhones and iPads with iCloud.

Utilities

  • Reflector: Reflector is a AirPlay Mirroring receiver. It’s the easiest tool to record the screen on iOS devices.
  • Transmit: Transmit is a FTP/SFTP/Amazon S3 client. It’s fast and powerful. It can also mount a connection to Finder.
  • Moom: Moom makes it easy to arrange and move windows. It’s more helpful with multiple displays.
  • Bartender: My menu bar was terribly crowded, but Bartender saves it.
  • SuperDuper!: It can make fully bootable backup for a Mac. I use SuperDuper! to keep a weekly backup on an external drive in my office.

2014 Wishes

I’m pretty satisfied with my Macbook and the apps I use on my Mac. Though there are some apps I haven’t listed as I don’t know whether I’ll use them over a long period of time.

I heard of pro tools like Hazel and Keyboard Maestro very often, but I’m always a bit afraid that I can’t settle with my own workflows. I want to find some time for them later this year.

Mavericks makes the Mac more powerful, high-performance and power saving in 2013. I wonder what OS X 10.10 will bring to Mac. I wish the interface can be more iOS 7-like, and AirDrop finally works between Mac and iOS devices.

Finally, I want to be a more productive person in both work and life this year. There are many things I want to learn, make and play in 2014. But productivity is not only about better tools and workflows, but most importantly, better habits and self-discipline.

Jan 19, 2014

如何用得起 MediaWiki

This is an article about how to run an affordable MediaWiki website. English version is coming.

MediaWiki 最初为运行维基百科而设计的开源程序,目前服务于超过一万的 Wiki 站点。神奇宝贝百科自2010年9月起运行于 MediaWiki,3年多来积累了很多心得,虽然内容和访问量迅速增长,但服务器开支依然保持在负担得起的范围。水跃希望在这里记录和分享。

日志标题中「用得起」的假设是运行在一台 1GB RAM 虚拟(云)服务器,日页面访问量在一百万以内。市场上 1GB RAM 的 VPS 价格约 10 ~ 30 美元每月。MediaWiki 并不适合运行在共享虚拟主机,或内存不到 512MB 的服务器中。

另外,MediaWiki 官方网站提供了一些基本的优化方式,非常值得参考。

MediaWiki 很耗资源么

是的。相较其他流行的 PHP 开源应用,MediaWiki 可以认为更耗资源,尤其是 CPU 使用,一篇包含复杂模板嵌套的文章,在无缓存状态下的渲染时间可能长达数秒,甚至数十秒。

经历了十多年的发展,MediaWiki 也是一个架构设计优雅的工程,具有非常强大的功能和可定制性,其性能开销往往是必要的。合理运用多重优化手段方式,可以有效降低 MediaWiki 的性能开销。

使用高性能的 Web 服务器程序

如果在生产环境使用最新版本的服务器程序,往往会引起很大的争议。但事实上,开源程序往往可以保持对较新版本系统环境很好的兼容性,新版本的系统环境往往具有更少的 Bug 和非常大的性能提升。

52Poké 所在的虚拟服务器采取了较为激进的做法,自2011年后一直使用 Arch Linux 操作系统,其滚动升级的特性可以让包管理(pacman)安装的应用都保持在最新版本,同时 Linode 也默认提供了最新版本的 Linux 内核。虽然对基础服务大版本的升级危险较大,但两年多来数十次 pacman -Syu 并未带来很大麻烦,除了在某几个凌晨造成数十分钟的不可用(都是由于较长时间未升级造成跨度较大并且操作失误)。

回到主题,对 MediaWiki 而言,高性能的 Web 服务器程序除了意味着 PHP 5.5,MySQL/MariaDB 5.5+;也包括使用 PHP 5.5 内置的 OPcache 加速,以及使用 Nginx + php-fpm 代替 Apache,Memcached 和/或 Redis 缓存等。

当前支持神奇宝贝百科的服务器程序为 PHP 5.5.7,MariaDB(MySQL 对社区友好的一个变体)5.5.34,Nginx 1.4.4 以及 Memcached 1.4.17。

合理的配置文件

MediaWiki 的默认配置(LocalSettings.php)并不适合生产环境,这里简要介绍一个低能耗的 MediaWiki 系统需要增加的配置项:

  • $wgDisableCounters = true; 关闭内置的统计功能,如需要统计访问量可以使用 Google Analytics 等外部服务。
  • $wgWellFormedXml = false; 以及 $wgHtml5 = true; 打开 HTML5 标签输出并关闭兼容 XML 语法,可以降低页面的体积。
  • $wgShowIPinHeader = false; 关闭未登录用户在右上角显示 IP 地址,以便使用静态缓存。
  • $wgUseGzip = true; 开启 gzip 压缩,降低页面体积,另外也可在 Web 服务器中配置开启 gzip。
  • $wgMiserMode = true; 关闭实时生成特殊页面;建议同时在 cron 里配置定时任务,定期生成特殊页面。
  • $wgJobRunRate = 0.01; 减少执行任务的频率(即每次请求有1%的几率运行任务);MediaWiki 的任务往往需要耗费数秒的时间执行,默认运行频率为1,一旦插入任务就可能导致 PHP 进程全部被占满;这里同样建议在 cron 里配置定时任务运行 MediaWiki 的任务,以免使任务队列积累过多。
  • $wgInvalidateCacheOnLocalSettingsChange = false; 关闭修改 LocalSettings.php 使所有缓存失效的特性;MediaWiki 的缓存完全失效是非常可怕的,几乎可以迅速致服务器僵死。

服务器端缓存

MediaWiki 的稳定运行,opcode 缓存、object 缓存和页面缓存都是必不可少的。

opcode 缓存

opcode 缓存用于加速 PHP 脚本的执行。PHP 5.5 内置了 OPcache(即之前的 ZendOptimizer+),比起 eAccelerator、XCache 和 APC 有更好的性能,只需在 php.ini 中引用 opcache.so 即可使用,同时 OPcache 也可单独安装在 PHP 5.4 或 5.3 环境中。另外需要注意 PHP 5.5.1 及 5.5.2 内置的 OPcache 和 MediaWiki 存在兼容问题,5.5.3 以上版本已解决。

object 缓存

MediaWiki 可以利用 object 缓存存储包括界面语言文字、文件信息、模板生成的中间产物、最终页面渲染 HTML 等数据。MediaWiki 支持使用 APC、XCache、Memcached、Redis、MySQL 数据库方式缓存数据,但配置中默认未开启 object 缓存功能。在这几种缓存方式中,除 MySQL 数据库外都需要在内存中存储,其中前3种存储方式无法持久化。

这里推荐使用是 Memcached 和 MySQL 结合的方式,配置方式如下:

$wgMainCacheType = CACHE_MEMCACHED;   
$wgMemCachedServers = array('127.0.0.1:11211');  
$wgParserCacheType = CACHE_DB;

Memcached 由于将数据存储在内存中,读写速度非常快;存储相同内容的数据占据的内存空间也是几种方式中最小。但 Parser Cache 由于包含了页面完整的 HTML 文本,需要的体积非常大,同时一旦失效则会需要重新解析所有页面,带来巨大的 CPU 开销;在内存有限的条件下更适合存储到较为持久的 MySQL 数据库中。

神奇宝贝百科在2013年初使用 Memcached 曾频繁遇到 Segfault,因此更换到 Redis + MySQL 结合的方式,但 Redis 耗费了更多内存(仅指在 MediaWiki 的使用方式下),也有相对较大的 I/O 使用。2013年12月 Memcached 发布了 1.4.17 更新,解决了不稳定的问题,因此目前又换回使用 Memcached。

页面缓存

作为一个 Wiki,对未登录用户而言页面几乎是静态的,所以页面缓存可以非常有效;MediaWiki 提供了 File cache 功能,另外也可以使用 SquidVarnish 的功能。而对于只有一台服务器的站点而言,这里更推荐使用 Nginx 自带的 FastCGI 缓存功能。

MediaWiki 默认会根据请求头中的 Accept-Language(即用户浏览器语言)、Cookie 等因素区分不同的页面缓存(可见响应头中的 Vary 行)。但对于单一语言、没有文字变种的 Wiki,只要已登录用户不使用页面缓存,未登录用户访问则看到相同的页面内容即可。

以下是神奇宝贝百科的 FastCGI 缓存配置,为便于介绍去掉了中文简繁处理相关的内容。这里缓存有效期为5小时,可以根据实际情况修改。另外,特殊页面不宜开启静态缓存(如最近更改和随机页面)。

http {
    ...
    fastcgi_cache_path  /var/cache/nginx/wiki levels=2:2 keys_zone=wiki:128m inactive=5h max_size=2048m;
    
    server {
        ...
        if ($http_cookie ~* "52poke_wikiUserID") {
            set $do_not_cache 1;
        }
        if ($uri ~ "^/wiki/Special:") {
            set $do_not_cache 1;
        }
        if ($args ~ "Special:") {
            set $do_not_cache 1;
        }
        fastcgi_cache wiki;
        fastcgi_ignore_headers Cache-Control Expires;
        fastcgi_hide_header Vary;
        fastcgi_cache_key $uri$is_args$args;
        fastcgi_cache_bypass $do_not_cache;
        fastcgi_no_cache $do_not_cache;
        fastcgi_cache_valid  200 5h;
        fastcgi_cache_valid  301 0;
        fastcgi_cache_valid  404 20m;
    }
}

使用页面缓存就会遇到缓存更新的问题,好在 MediaWiki 提供了 PURGE 功能,配置后只要相应的页面有更新就会发出 HTTP PURGE 请求。LocalSettings.php 中的配置如下:

$wgUseSquid = true;
$wgSquidServers = array('127.0.0.1’);

这里只配置了 127.0.0.1 因 52Poké 只有一台前端服务器,并且和 MediaWiki 程序是同一台。不过 Nginx 默认并不支持 PURGE 请求,可以编译安装 ngx_cache_purge 扩展实现,具体操作步骤可以参考这里

对于具有文字变种,如中文简繁之分的 Wiki,则情况较为复杂,今后这里会详细讨论 MediaWiki 处理中文简繁的问题,本篇就不详述了。

减少模板和文章内容渲染的开销

MediaWiki 提供了非常强大的模板和语法处理功能,尤其是内置的 ParserFunctions 扩展,但语法解析需要非常大的 CPU 开销。

这里建议尽可能减少不必要的模板使用和嵌套。例如对于一些通用的文字、背景颜色、边框样式,更适合在 MediaWiki:Common.css 或小工具中使用 CSS 实现。如果文章在编辑后需要等待很长的时间才能加载出来,则需要对其中使用的模板进行优化,必要时可以考虑拆分文章。

MediaWiki 解析图片信息也需要较大的资源消耗,对于较为固定的图片、尤其是尺寸较小的图片,推荐使用 CSS Sprites 而非通过 Wiki 上传。

MediaWiki 也会对包含过多模板嵌套、或者使用了过多语法呼叫(例如 switch 和 if 语法)的文章自动添加警示的分类。

选择合适的服务商

基础硬件的性能往往是第一位的,对运行 MediaWiki 而言,CPU、内存、I/O 性能、网络带宽都至关重要。其实早在2006年 52Poké 就搭建了 MediaWiki,但在有上百篇文章之后当时所在的虚拟主机就不堪重负,不得不在后来转型使用自建的程序,直到2010年开始使用 Linode。

就 52Poké 使用 Linode(推介链接) 的经历而言,Linode 是一家不错的 VPS 提供商,但并不算完美。Linode 在2013年进行了多次升级,在流量、网络速度、CPU 性能和性价比方面有较大优势。

VPS 有一个不稳定因素是 CPU 和 I/O 性能会受同一台物理服务器的邻居影响,52Poké 曾遇到过 CPU %Steal 过高导致性能较差的问题,不过联系客服很快迁移了另一台物理服务器解决。Linode 的 I/O 性能比提供了 SSD 的服务商要差,目前 Linode 只在纽瓦克数据中心提供了测试版 SSD 服务,亚洲用户较多使用的东京数据中心则尚未提供。

其他和未来

到这里已经介绍了高性能 MediaWiki 站点的必要条件。不过对于拥有较多图片的 Wiki 来说,可能很容易遇到流量超限或 I/O 消耗较大的问题,推荐如有必要添加一台流量较为廉价的 VPS 存放或缓存图片;另外可以考虑将图片延迟加载,即当浏览者滚动到图片位置时再加载,该功能的 MediaWiki 扩展在完成开发后会开源。

关于 MediaWiki,除了性能之外,还有很多值得讨论的话题。比如扩展,小工具(Gadget),中文的繁简问题,条目命名和内容规范,自动化批量建设内容,版权问题,以及作为一个 Wiki 社群的建设和发展。这些就留在以后继续讨论吧。

对于未来,如何支持移动设备,如何进一步减少服务器端模板的开销是水跃在继续思考的问题。MediaWiki 官方提供了 MobileFrontend 扩展,但根据设备输出不同的内容会带来更多的复杂度和资源消耗,而且可能降低了移动设备的体验;所以我更希望有响应式的方案。对于复杂的表格如果可以服务器只在页面中输出元数据,由 JavaScript 在浏览器中渲染的话,就可以减轻服务器的压力。但修改 Wiki 的 JavaScript 和 CSS 的权限往往不会开放给普通用户,这样做对社区并不利。

2014年的第一篇终于啰嗦完了,这里祝各位新年快乐,也希望 MediaWiki 的同好有所收获吧: )

Jan 5, 2014

Next time… A new beginning!

Writing more is one of my failed 2013 resolution, and I know lack of time can’t be a convictive excuse. I love the open web. I like owning my identity and this precious domain. So this time I decide to restart this blog, and I vow to update mudkip.me frequently from now on.

After I think this restart thing through, I made some decisions. The first is staying on Tumblr. I looked at alternatives like Jekyll/Ghost, and I love WordPress, especially after the 3.8 release and I wrote the new theme of 52poke.com. But Tumblr is still the perfect choice for personal blogs. I followed a lot of interesting accounts and there are many posts I want to like or reblog. It’s also easier to do link or image posts here than anywhere else.

The bigger question is what to write. I always feel this blog should be personal and emotional. In the past few years I also tried to write something argumentative, as I had some strong opinions about things like Nintendo, region-lock or copyright. But this blog should be bigger.

Besides the Pokémon news I write on 52Poké, I have more I like to share. This restarted blog will contain more topics, and in particular, technology. I’ve learned a lot in the past few years, either from my work or the lovely stuff I do for 52Poké. I can’t wait to write about them. Geeks like me care a lot about the tools we use. As I just start to create my workflow, I want to share my setup (again) in a foreseeable future.

My English skill is still bad and between en–2 to en–3, and I’m too shy to write about some topics in my native language. So I’ll still write in either Chinese or English, or both. I want this blog have a broad audience who have anything in common with me, either my beloved friends in 52Poké, or geeks who like web technologies or Apple devices, or Peter Pan syndrome kidults who never grow up.

2013年一个很大的遗憾是没有坚持写Blog的习惯。并没有特别的原因和借口,纯粹是因为忽视甚至渐渐遗忘了这里。但 mudkip.me,这个只属于自己的地方对我来说依然很重要,所以想要在这里再次开始。

这些天一直在思考「重新开始写Blog」这件事,面临的第一个选择就是平台。静态化的Jekyll,使用Node.js的Ghost都有接触过;而WordPress我也非常喜欢,尤其是3.8的种种改进以及神奇宝贝部落格重制了新主题。但最终的决定还是继续留在Tumblr,Tumblr同时具备了Blog平台和社交网络的优势,可以很容易的点赞和转发,而且支持图片、链接、对话格式的内容。

但更重要的问题是这个Blog的主题。最初觉得Blog是一种像日记本一样私人的东西,后来在许多问题上有想要说出来的看法,尤其是对任天堂锁区的吐槽在一两篇推文的长度又无法满足。但其实Blog应该不止于此,还有更多想要记录下来的东西。

重制之后的mudkip.me当然会包含更多的主题,尤其是科技方面的话题。过去在工作中和部落格许多事情上学到了很多东西想要分享出来,作为Geek也有很多想要讨论的设备、工具以至生活方式。当然,日常生活和吐槽依旧是这里不可缺少的一部分。

希望这里能吸引和水跃自己有共同点的读者们,不管是52Poké的大家,喜爱Web技术的各位,还是和我一样不会长大的死宅。我的英文依旧很糟,但看得出母语的表达能力也相当糟糕,所以这里依然会混杂着中文和英文。

那么,一个新的开始,以及新年快乐: )

Dec 29, 2013

Christmas is drawing near.

Nov 28, 2013

Copyright © 2014 mudkip.me