Interprocess Communication Affects Application Response Time

Interprocess Communication Affects Application Response Time

Randy Stafford

RESPONSE TiME iS CRiTiCAL TO SOFTWARE USABiLiTY. Few things are as frustrating as waiting for some software system to respond, especially when our interaction with the software involves repeated cycles of stimulus and response. We feel as if the software is wasting our time and affecting our pro- ductivity. However, the causes of poor response time are less well appreciated, especially in modern applications. Much performance management literature still focuses on data structures and algorithms, issues that can make a differ- ence in some cases but are far less likely to dominate performance in modern multitier enterprise applications.
When performance is a problem in such applications, my experience has been that examining data structures and algorithms isn’t the right place to look for improvements. Response time depends most strongly on the number of remote interprocess communications (IPCs) conducted in response to a stimulus. While there can be other local bottlenecks, the number of remote interprocess communications usually dominates. Each remote interprocess communication contributes some nonnegligible latency to the overall response time, and these individual contributions add up, especially when they are incurred in sequence.
A prime example is ripple loading in an application using object-relational mapping. Ripple loading describes the sequential execution of many database calls to select the data needed for building a graph of objects (see Lazy Load* in Martin Fowler’s Patterns of Enterprise Application Architecture [Addison- Wesley Professional]). When the database client is a middle-tier application server rendering a web page, these database calls are usually executed sequen- tially in a single thread. Their individual latencies accumulate, contributing to the overall response time. Even if each database call takes only 10 milliseconds,
* http://martinfowler.com/eaaCatalog/lazyLoad.html
82 97 Things Every Programmer Should Know

a page requiring 1,000 calls (which is not uncommon) will exhibit at least a 10-second response time. Other examples include web-service invocation, HTTP requests from a web browser, distributed object invocation, request– reply messaging, and data-grid interaction over custom network protocols. The more remote IPCs needed to respond to a stimulus, the greater the response time will be.
There are a few relatively obvious and well-known strategies for reducing the number of remote interprocess communications per stimulus. One strat- egy is to apply the principle of parsimony, optimizing the interface between processes so that exactly the right data for the purpose at hand is exchanged with the minimum amount of interaction. Another strategy is to parallelize the interprocess communications where possible, so that the overall response time becomes driven mainly by the longest-latency IPC. A third strategy is to cache the results of previous IPCs, so that future IPCs may be avoided by hit- ting local cache instead.
When you’re designing an application, be mindful of the number of interprocess communications in response to each stimulus. When analyzing applications that suffer from poor performance, I have often found IPC-to-stimulus ratios of thousands-to-one. Reducing this ratio, whether by caching or parallelizing or some other technique, will pay off much more than changing data structure choice or tweaking a sorting algorithm.

Android的Interprocess Communication (IPC)是通过Binder机制来实现的,而Binder机制的底层实现就是Interprocess Communication Over Non-Contiguous Memory(非连续内存的进程间通信)。 Binder机制的核心是Binder驱动,它提供了一个通信通道,使得不同进程之间可以相互通信。Binder驱动通过内核映射机制将进程间传递的数据缓存区映射到物理内存中,并通过共享内存的方式将这些缓存区连接起来,从而实现IPC。 在Binder机制中,进程间通信的主要对象是Binder对象。每个Binder对象都有一个唯一的标识符,称为Binder引用。当一个进程需要与另一个进程通信时,它需要获取对方进程中的Binder对象的引用,然后通过Binder驱动进行通信。 在跨进程调用时,调用方进程需要将参数数据传递给被调用方进程,并等待被调用方进程返回结果数据。为了避免内存拷贝带来的性能损失,Binder机制采用了共享内存的方式来传递数据。具体来说,当调用方进程需要将参数数据传递给被调用方进程时,它会将参数数据写入一个缓存区,并向Binder驱动注册这个缓存区。被调用方进程可以通过Binder驱动获取这个缓存区的引用,然后直接访问该缓存区中的数据。 总之,Android的IPC机制是通过Binder驱动实现的,它利用非连续内存的技术来实现进程间通信,从而大大提高了Android系统的性能和稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值