Nginxでリバースプロキシするときに、バックエンドに同時に1つしか同じリクエストが行かないようにする方法
注意
うろ覚えなので間違っているかもしれない
本文
ここ http://www.1x1.jp/blog/2013/12/varnish-cache.html に
当初、nginx の proxy_cache を試したのですが、同一 URL へ多数のリクエストが来ている状況でキャッシュのライフタイムが切れると、バックエンドへ同じ URL に対して複数のリクエストが飛んでしまい、PHP アプリケーション側に負荷がかかるという現象があったので、今回は取りやめました。
Varnish では、同一 URL に対して複数のリクエストがあっても、バックエンドへは 1 リクエストしか飛ばないようになっている。
とあったけど確かそれnginxでもできたと思いました。
http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache_lock
When enabled, only one request at a time will be allowed to populate a new cache element identified according to the proxy_cache_key directive by passing a request to a proxied server. Other requests of the same cache element will either wait for a response to appear in the cache or the cache lock for this element to be released, up to the time set by the proxy_cache_lock_timeout directive.
これ使えばできると思う。
ただし、
This directive appeared in version 1.1.12.
となっていて、CentOS 5系だと自分でnginxビルドしないと使えないみたいな感じだった気がする。
MacBook AirのSSDが壊れるまでの記録
先週まで
- いつの間にか
/DamagedFiles
と/lost+found
ができていた。- 2013/10/14 00:00のバックアップには無かったが、2013/10/15 01:35には有った
- フタを閉じてスリープしておいたのに、次に開いたら電源が落ちている事が何度かあった
金曜
- 外付けUSBHDDにTimeMachineバックアップを新規作成した
土曜
ls /usr/local
したらターミナルがフリーズする現象が発生- ファイルシステム破損?
- パーティションを消去してTimeMachineバックアップから丸ごと復元した
日曜
月曜
- Appleに電話して修理の手続きした
備考
- https://twitter.com/fumikony/status/394337357626740737
- ファイルシステムが壊れたのとSSDが壊れたのの因果関係は不明
- パーティション消してから復元した直後のTimeMachineバックアップは時間がかかる
test
hoge
piyo
- foo
- bar
def a(b) nil end
「システム環境設定」の実体
「パーソナル」から「システム」までは /System/Library/PreferencePanes にある.
「その他」のうち全ユーザ共通のものは /Library/PreferencePanes に,
ユーザ毎のものは ~/Library/PreferencePanes にあるようだ.
% ls /System/Library/PreferencePanes Accounts.prefPane/ Appearance.prefPane/ Bluetooth.prefPane/ DateAndTime.prefPane/ DesktopScreenEffectsPref.prefPane/ DigiHubDiscs.prefPane/ Displays.prefPane/ Dock.prefPane/ EnergySaver.prefPane/ Expose.prefPane/ FibreChannel.prefPane/ Ink.prefPane/ Keyboard.prefPane/ Localization.prefPane/ Mac.prefPane@ MobileMe.prefPane/ Mouse.prefPane/ Network.prefPane/ ParentalControls.prefPane/ PrintAndFax.prefPane/ Security.prefPane/ SharingPref.prefPane/ SoftwareUpdate.prefPane/ Sound.prefPane/ Speech.prefPane/ Spotlight.prefPane/ StartupDisk.prefPane/ TimeMachine.prefPane/ Trackpad.prefPane/ UniversalAccessPref.prefPane/ % ls /Library/PreferencePanes Air Display Preferences.prefPane/ Flash Player.prefPane/ Growl.prefPane/ KeyRemap4MacBook.prefPane/ MacUIM.prefPane/ PCKeyboardHack.prefPane/ TeXDistPrefPane.prefPane/ % ls $HOME/Library/PreferencePanes GeekTool.prefPane/ teleport.prefPane/
run(10 * second) した後でt > 9[s] についてraster_plot()する
from brian import * all_neurons = NeuronGroup('省略') moni_spike_all = SpikeMonitor(all_neurons) run( 10 * second ) spikes = [s for s in moni_spike_all.spikes if s[1] >= 9*second] raster_plot_spiketimes(spikes) show()
raster_plot_spiketimesについて.
In [42]: raster_plot_spiketimes?? Type: function Base Class: <type 'function'> String Form:<function raster_plot_spiketimes at 0x106e49848> Namespace: Interactive File: /Library/Python/2.6/site-packages/brian/plotting.py Definition: raster_plot_spiketimes(spiketimes) Source: def raster_plot_spiketimes(spiketimes): """ Raster plot of a list of spike times """ m = Monitor() m.source = [] m.spikes = spiketimes raster_plot(m) t = array(spiketimes)[:,1]