how RoR scales

本文讨论了Ruby on Rails应用的可扩展性策略,借鉴了如Yahoo!等大型网站的经验。通过去除应用程序服务器的状态并利用负载均衡器实现水平扩展。文章进一步探讨了在不同技术栈间的成本效益对比,并强调了开发效率的重要性。

转载自DHH的blog http://www.loudthinking.com/arc/000479.html

 

I've said it before, but it bears repeating: There's nothing interesting about how Ruby on Rails scales. We've gone the easy route and merely followed what makes Yahoo!, LiveJournal, and other high-profile LAMP stacks scale high and mighty.

Take state out of the application servers and push it to database/memcached/shared network drive (that's the whole Shared Nothing thang). Use load balancers between your tiers, so you have load balancers -> web servers -> load balancers -> app servers -> load balancers -> database/memcached/shared network drive servers. (Past the entry point, load balancers can just be software, like haproxy).

In a setup like that, you can add almost any number of web and app servers without changing a thing.

Scaling the database is the "hard part", but still a solved problem. Once you get beyond what can be easily managed by a decent master-slave setup (and that'll probably take millions and millions of pageviews per day), you start doing partitioning.

Users 1-100K on cluster A, 100K-200K on cluster B, and so on. But again, this is nothing new. LiveJournal scales like that. I hear eBay too. And probably everyone else that has to deal with huge numbers.

So the scaling part is solved. What's left is judging whether the economics of it are sensible to you. And that's really a performance issue, not a scalability one.

If your app server costs $500 per month (like our dual xeons does) and can drive 30 requests/second on Rails and 60 requests/second on Java/PHP/.NET/whatever (these are totally arbitrary numbers pulled out of my...), then you're faced with the cost of $500 for 2.6 million requests/day on the Rails setup and $250 for the same on the other one.

Now. How much is productivity worth to you? Let's just take a $60K/year programmer. That's $5K/month. If you need to handle 5 million requests/day, your programmer needs to be 10% more productive on Rails to make it even. If he's 15% more productive, you're up $250. And this is not even considering the joy and happiness programmers derive from working with more productive tools (nor that people have claimed to be many times more productive).

Of course, the silly math above hinges on the assumption that the whateverstack is twice as fast as Rails. That's a very big if. And totally dependent on the application, the people, and so on. Some have found Rails to be as fast or faster than comparable "best-of-breed J2EE stacks".

The point is that the cost per request is plummeting, but the cost of programming is not. Thus, we have to find ways to trade efficiency in the runtime for efficiency in the "thought time" in order to make the development of applications cheaper. I believed we've long since entered an age where simplicity of development and maintenance is where the real value lies.

其实正如zhangc之前说,理论的问题都清楚,关键还是实践!

05-10
<think>好的,我现在需要帮助用户理解ROR指令在汇编语言中的功能和用法。用户已经提供了相关的引用内容,我需要仔细分析这些引用,并结合我的知识来给出准确的回答。 首先,查看引用中的信息。引用[3]提到移位指令,当移位次数大于1次时,需要用CL寄存器来指定次数,例如“SHL AX,CL”。同时,引用[3]还提到了ROR作为循环右移指令,属于移位指令的一种。引用[4]中虽然没有直接提到ROR,但提到了其他标志位操作指令,比如CLC、STC等,这可能与ROR执行后的标志位影响有关。 接下来,用户的问题是关于ROR指令的功能和用法。根据引用[3],ROR是循环右移指令,每次移位将最低位移动到最高位,同时影响进位标志CF。例如,ROR AX,1会将AX的内容循环右移一位。如果移位次数超过1次,需要使用CL寄存器来指定次数,如ROR AX,CL。 然后,我需要确认ROR的具体行为。循环右移是指每一位向右移动,最低位(LSB)移动到最高位(MSB),同时原来的最高位进入进位标志CF。例如,假设AX是8位的话,二进制为10000000,执行ROR AX,1后,变为01000000,并且CF被设置为1,因为移出的位是0?或者可能需要具体例子来验证。不过根据汇编的一般知识,ROR确实是这样工作的。 此外,引用[3]还提到了其他移位指令,如SHL(逻辑左移)、SHR(逻辑右移)、ROL(循环左移)和ROR(循环右移),这些指令在操作数方面类似,都是可以指定立即数或CL寄存器作为移位次数。 用户可能还想知道ROR的应用场景。例如,循环移位常用于加密算法、位操作或者处理需要循环移位的场合。比如,在CRC计算或者某些位模式的重排中可能会用到ROR。 还需要注意,ROR执行后会影响标志位,尤其是CF和OF(溢出标志)。每次移位后,CF会被设置为最后移出的位,而OF仅在移位次数为1时有意义,表示符号位是否改变。 现在需要将这些信息整理成结构化的回答,包括功能、语法、标志位影响、应用场景和相关问题。同时,要确保使用正确的LaTeX格式,行内公式用$...$,独立公式用$$...$$,并引用正确的来源。 可能还需要验证引用中的信息是否准确。例如,引用[3]明确提到ROR属于移位指令,并且说明了移位次数由CL寄存器指定的情况,这与我的知识一致。因此可以确定ROR的功能和用法如引用所述。 总结回答的结构:首先解释ROR的定义,然后详细说明其功能,包括操作方式、语法示例、标志位影响,接着给出应用场景,最后生成相关问题。同时,引用相关的引用来源,如引用[3]和可能的其他引用。</think>### **ROR指令在汇编语言中的功能与用法解析** --- #### **1. ROR指令的定义与核心功能** **ROR**(**R**otate **R**ight)是汇编语言中的**循环右移指令**,属于**位操作指令**。其核心功能是将操作数的二进制位**整体向右循环移动**,**最低位(LSB)移动到最高位(MSB)**,同时**移出的位会存入进位标志CF**中[^3]。 例如,若寄存器`AX`的值为`10000000`(二进制),执行`ROR AX, 1`后,结果变为`01000000`,且`CF=0`(移出位为0)。 --- #### **2. 语法格式与操作规则** - **基本语法**: ```assembly ROR 目标操作数, 移位次数 ``` - **操作数类型**: - **目标操作数**:可以是寄存器(如`AX`, `BX`)或内存单元。 - **移位次数**: - **单次移位**:直接指定立即数(如`ROR AX, 1`)。 - **多次移位**:需通过`CL`寄存器指定次数(如`MOV CL, 3` → `ROR AX, CL`)[^3]。 --- #### **3. 标志位影响** ROR指令执行后会影响以下标志位: - **CF(Carry Flag)**:记录最后一次移出的位值。 - **OF(Overflow Flag)**: - **仅当移位次数为1时有效**:若最高两位在移位后不同,则`OF=1`(表示符号位变化);否则`OF=0`[^3][^4]。 - **其他标志位**(如ZF, SF等)不受影响。 --- #### **4. 典型应用场景** 1. **加密算法**:在循环加密或位混淆中,利用循环移位改变数据位模式。 2. **位操作优化**:快速处理位字段的重新排列或掩码生成。 3. **硬件控制**:与设备寄存器交互时,通过移位操作特定状态位。 --- #### **5. 示例代码** ```assembly MOV AX, 0x8000 ; AX = 10000000 00000000 (二进制) ROR AX, 1 ; AX → 01000000 00000000,CF=0 ROR AX, 3 ; 需通过CL寄存器:MOV CL, 3 → ROR AX, CL ``` --- ### **相关问题** 1. **ROR与SHR指令有何区别?** (提示:`SHR`为逻辑右移,空出的高位补0;`ROR`为循环右移,最低位移至最高位[^3]) 2. **如何用ROR实现多字节数据的循环移位?** (提示:结合`RCR`指令处理进位标志链式传递[^2][^4]) 3. **循环移位指令在加密算法中的具体应用?** (提示:如DES算法中的Feistel网络轮函数[^3]) --- 以上解析基于汇编语言移位指令规范及引用资料[^3][^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值