注意:
ACE网络框架比较有名,30万行左右代码,开发了10几年,数十人的核心开发团队加之数千人的测试队伍,可以说想不开发出好东西也难。
所以要说这个框架好,那好的原因实在太多,最主要的好在于两条:“跨平台(支持几十种平台),可复用”,所以今日说说我认为他不足的地方,以作为这段时间学习它的一个总结:
国内有三本和ACE框架有关的书,我都读了,整个加起来读了能有10几不到20天,读完后我分别写了一个比较简单的Reactor-Connector框架的客户端程序和一个Proactor框架的服务器程序,以作为对所学知识的运用。发觉用ACE写服务器端程序比写客户端程序顺手。顺便把服务器程序测试了一下,在本机上用client连接,服务器支持的最大连接数为16160,程序逻辑问题,没出现异常情况,基本满意。
整个觉得这个框架想流行起来有一定难度:
(1)复用类和框架是它所提倡的,表面看,这些框架简化了程序开发,让开发人员能够专注于解决问题,但真正用这些框架开发程序的时候,要想开发出稳定的程序,就不可避免的要对框架深入理解,结果就深入的学进去了,这一学,哎呀发现它还的源代码还挺复杂,结果,违背了研究它的初衷(简化开发)。
(2)封装和复用是这几年流行的开发术语,封装和复用也许是不错,是好用,但对于学习的人来讲,真的很难学,这么多个类结合到一起来,让人一时半刻不好掌握。
(3)要想学好ACE的开发需要很好的网络开发基础,如果你没有网络开发基础,想通过学习这个框架来使自己能够省更多力气就可以开发网络程序,我想恐怕您会失望。
(4)ACE框架不够灵活,有时候想改一些东西,但涉及到改动ACE源代码不免挠头,我觉得他的代码还是挺难看的,我们每个人的生命有限,时间有限,有多少时间坐那里读几十万行代码。
(5)ACE框架把各平台的应用又统一封装了一下,和专有平台代码比,我认为效率还是要低一些,尽管目前计算机运算速度飞快。
原来我是计划用ACE框架作为以后开发网络应用的框架,后来想了想,还不如用传统的开发直观,可控性强,因为我的开发基本不跨平台,好了,就总结这些先。
===================================================================================
1.学习ACE要看书,初学者学习ACE没有什么捷径,如果有的话,那么就是看书了。
目前国内中翻本的ACE专门书籍一共有5本,个别书籍在书店不太好买到,在当当淘宝都可以取得。
不过还是推荐日后有能力的话,阅读原版,原版的电子书基本上都可以从官方网站上获得。
http://www.cs.wustl.edu/~schmidt/ACE-documentation.html 。
a)CppNetwork Programming Volume I,Mastering Complexity With ACE and Patterns
C++网络编程卷1(C++NPV1)
注:ACE的基础入门书籍,主要讲解ACE提供的对各平台系统底层系统接口的包装(wrapper facade)。
如socket,进程,线程,同步机制等。
这应该是你需要了解的第一本关于ACE的书,本书中提出了ACE作者对于网络问题的研究,分为四个设计空间:网络、并发、服务、配置。本书核心讲述网络和并发应用程序的开发,及其ACE与之对应的Wrapper Facade Class,并以一个日志服务器实例作为演示,使用多种方式实现该日志服务器(实例代码参见,ACE_Wrapper/examples/C++NPv1)。(关于Wrapper Facade 模式可以参考《POSA 卷2》,具体优缺点不在此赘述了)。
b)CppNetwork Programming Volume II, Systematic Reuse with ACE and Frameworks
C++网络编程卷2(C++NPV2)
注:初步了解ACE之后,如果ACE确实你需要的,这本书绝对值得通读3遍5遍以上。
这本书详细讲解ACE提供的主要框架(Framework)的运作原理,实在是ACE程序员居家旅行的必备良品。
本书核心内容主要讲述《C++NPv1》中分出的四个设计空间中的:服务器设计空间和配置设计空间,及ACE基于Wrapper Facade的框架实现。如:Connector-Acceptor、Reactor、Proactor、Stream、Service Configurator等。对应于ACE的框架层。
c)ACE Programmer's Guide, The Practical Design Patterns for Network and Systems Programming
ACE程序员指南(APG)
注:这本书更偏重于ACE的使用,展示了如何运用ACE快速完成自己的需求。
强烈建议在了解C++NPV1,2的基础上阅读。
大致了解以上三本书之后,基本上再遇到问题的时候,就不会感到手足无措了。
d)ACE自适配通信环境中文技术文档(马维达)
本书分三卷,上卷与中卷主要讲基础知识,与前三本书有相辅相成的作用,
下卷主要介绍ACE开发组开发的,基于ACE的几个高级应用,包括Gateway,JAWS,TAO。
注:这并不是取自一本书,感谢译者把取自 http://www.cs.wustl.edu/~schmidt/ACE-papers.html 的
ACE多篇技术文档整理并翻译出来,不过由于某种原因,作者仅把译文的电子版发布到网络上,
并没有出版中文实体书。
下面这些资料,都是网上一些热爱ACE的人整理的。因为ACE对于网络程序开发有非常大的影响,Douglas C. Schmidt及其ACE热爱者关于ACE也写了不少论文,同时使用ACE实作了很多的应用实例。(多数实例都可以在ACE的源码目录下example、app目录下找到)
- 上篇-ACE技术论文集
- 中篇-ACE程序员教程
- 下篇-ACE应用实例
e)Pattern-Oriented Software Architecture Volume II: Patterns for Concurrent and Networked Objects
面向模式的软件架构卷2
注:这本书主要讲解C++NPv2提供的各种framework的设计缘由,如果说C++NPV2告诉我们各种framework是什么
和如何使用,那么从这本书我们将知道为什么是这样设计,这本书适合对ACE有相当的了解程度之后阅读。
2.如果你手里还没有ACE的源代码,可以从 http://download.dre.vanderbilt.edu/ 获得最新版的源代码。
ACE是开源项目,不过使用ACE不需要任何linsence并且不受任何类似GPL的限制。
你可以在学习、工作、甚至商业项目中任意使用ACE,只要包含其版权声明就可以了,
无需承担任何其他的义务。
3.在解压源代码之后,假设你的ACE_wrappers所在目录为$ACE_ROOT,ACE_ROOT/ace是源代码目录。
根据自己平台的特性在$ACE_ROOT/ace目录下配置好config.h,就可以开始你的ACE旅程了。
windows下,只需配置configh就可以了,linux下参考下面的文档。
http://www.acejoy.com/bbs/viewthread.php?tid=847&extra=page%3D1
各平台的具体细节,这里不再重复,需要说明的是config.h的各平台的配置开关,
可以参考$ACE_ROOT/ace/Readme。
4.打开$ACE_ROOT/examples,这里存放着ACE开发组提供的非常实用的例子,首先你会看到
APG,C++NPV1,2等子目录,眼熟吧,在这些目录下存放了前三本书里提到的所有的示例程序。
你不用再敲一遍了代码了,学习的时候,拿过来直接用就可以了。
其他的例子,随着对ACE的慢慢熟悉,根据自己的需求会逐渐的用到。
$ACE_ROOT/app目录下,包含前面第四本书提到的Gateway与JAWS的应用源代码。
JAWS是ACE开发组提供的基于ACE的高性能的webservice框架。
Gateway是ACE开发组提供的基于ACE的应用级网关。
$ACE_ROOT/TAO目录下,包含了TAO的源代码。
THE ACE ORB(TAO)是ACE开发组提供的基于ACE的CORBA的实现。
5.随着对ACE的认识的逐渐深入,可能逐渐遇到很多细节的问题,推荐在开始阅读源代码之前,
还是先回来翻翻书,特别是C++NPV2,很多时候费了好多时间与精力,在阅读源代码之后,
解决了一个问题,偶尔回头翻开书,原来书上已经说得很清楚了, 只是以前看的时候,
没有注意到而已。当然如果有精力的话,阅读ACE的源代码还是大滋大补的,
尤其平台之间存在诸多细微的细节差异,这些都源于操作系统底层的API的实现。
对于系统底层API的特性理解是,随着对ACE掌握能力的提高的必经之路。
6.本站(ACEJOY)提供了站内搜索功能,对于很多初学者来说,很多问题基本上都共性,
学习ACE遇到问题,搜一下说不定别人已经遇到过了,而且有了解决方案。
说实话本人经常使用站内搜索功能,一些具体的ACE的使用问题,有时候比直接google来得快。
最后,希望的我这篇文章对你了解与学习ACE会有帮助,欢迎使用www.acejoy.com/bbs。
7. ACE官方介绍
http://www.cs.wustl.edu/~schmidt/ACE-overview.html
Overview of ACE
The ADAPTIVE Communication Environment(ACE) is a freely available, open-sourceobject-oriented (OO) framework that implements many core patterns for concurrent communicationsoftware. ACE provides a rich set of reusable C++ wrapper facades and frameworkcomponents that perform common communication software tasks across arange of OS platforms. The communication software tasks provided byACE include event demultiplexing andevent handler dispatching, signalhandling, serviceinitialization, interprocesscommunication, shared memory management, message routing, dynamic (re)configuration of distributedservices, concurrentexecution and synchronization.
ACE is targeted for developers of high-performance and real-timecommunication services and applications. It simplifies thedevelopment of OO network applications and services that utilizeinterprocess communication, event demultiplexing, explicit dynamiclinking, and concurrency. In addition, ACE automates systemconfiguration and reconfiguration by dynamically linking services intoapplications at run-time and executing these services in one or moreprocesses or threads.
ACE continues to improve and its futureis bright. ACE is supported commercially by multiple companies using an open-source business model. Inaddition, many members of the ACEdevelopment team are currently working on building The ACEORB (TAO).
Benefits of Using ACE?
Some of the many benefits of using ACE include:
- Increased portability -- ACE components make it easy towrite concurrent networked applications on one OS platform and quicklyport them to manyother OS platforms. Moreover, because ACE is open source, free software, you never have to worryabout getting locked into a particular operating system platform orcompiler configuration.
- Increased software quality -- ACE components are designedusing many key patterns that increasekey qualities, such as flexibility, extensibility, reusability, andmodularity, of communication software.
- Increased efficiency and predictability -- ACE iscarefully designed to support a wide range of application quality ofservice (QoS) requirements, including low latency for delay-sensitiveapplications, high performance for bandwidth-intensive applications,and predictability for real-time applications.
- Easier transition to standard higher-level middleware --ACE provides the reusable components and patterns used in The ACE ORB(TAO), which is an open-sourcestandard-compliant implementation of CORBA that's optimized forhigh-performance and real-time systems. Thus, ACE and TAO aredesigned to work well together in order to provide comprehensivemiddleware solutions.
The Structure and Functionality of ACE
The following diagram illustrates the key components in ACE and theirhierarchical relationships:
The structure and participants of the layers in this diagram aredescribed below.
The ACE OS Adapter Layer
This layer resides directly atop the native OS APIs that are writtenin C. It provides a smallfootprint, "POSIX-like" OS adaptation layer that shields the otherlayers and components in ACE from platform-specific dependenciesassociated with the following OS APIs:
- Concurrency and synchronization -- ACE's adaptation layerencapsulates OS APIs for multi-threading, multi-processing, andsynchronization.
- Interprocess communication (IPC) and shared memory --ACE's adaptation layer encapsulates OS APIs for local and remote IPCand shared memory.
- Event demultiplexing mechanisms -- ACE's adaptation layerencapsulates OS APIs for synchronous and asynchronous demultiplexingI/O-based, timer-based, signal-based, and synchronization-basedevents.
- Explicit dynamic linking -- ACE's adaptation layerencapsulates OS APIs for explicit dynamic linking, which allowsapplication services to be configured at installation-time orrun-time.
- File system mechanisms -- ACE's adaptation layerencapsulates OS file system APIs for manipulating files anddirectories.
The portability of ACE's OS adaptation layer enables it to run on amany operating systems. ACE has been portedand tested on a wide range of OS platforms including Windows (i.e., WinNT 3.5.x, 4.x,2000, Embedded NT, XP, Win95/98, and WinCE using MSVC++, Borland C++Builder, and IBM's Visual Age on 32- and 64-bit Intel and Alphaplatforms), Mac OS X, mostversions of UNIX (e.g., Solaris onSPARC and Intel, SGI IRIX 5.x and6.x, DG/UX, HP-UX 10.x, and 11.x, Tru64UNIX 3.x and 4.x, AIX 3.x,4.x, 5.x, DG/UX, UnixWare, SCO, andfreely available UNIX implementations, such as Debian Linux 2.x, RedHat Linux 5.2, 6.x, 7.x, 8x, and9.x, as well as the various Enterprise editions, SUSE Linux 8.1and 9.2, Timesys Linux, FreeBSD, and NetBSD), real-time operating systems(e.g., LynxOS, VxWorks, ChorusOS, QnX Neutrino, RTEMS, OS9,and PSoS), OpenVMS, MVSOpenEdition, and CRAY UNICOS. A single sourcetree is used for all these platforms. There is also a Java version ofACE.
Because of the abstraction provided by ACE's OS adaptation layer, asingle sourcetree is used for all these platforms. This design greatlysimplies the portability and maintainability of ACE.
C++ Wrapper Facades for OS Interfaces
It is possible to program highly portable C++ applications directlyatop ACE's OS adaptation layer. However, most ACE developers use theC++ wrapper facade layer shown in the figure above. The ACE C++wrapper facades simplify application development by providing typesafeC++ interfaces that encapsulate and enhance the native OS concurrency,communication, memory management, event demultiplexing, dynamiclinking, and file system APIs. Applications can combine and composethese wrappers by selectively inheriting, aggregating, and/orinstantiating the following components:
- Concurrency and synchronization components -- ACEabstracts native OS multi-threading and multi-processing mechanismslike mutexes and semaphores to create higher-level OO concurrency abstractions like ActiveObjects and Polymorphic Futures.
- IPC and filesystem components -- The ACE C++ wrappersencapsulate local and/or remote IPCmechanisms, such as sockets, TLI, UNIX FIFOs and STREAM pipes, andWin32 Named Pipes. In addition, the ACE C++ wrappers encapsulate theOS filesystem APIs.
- Memory management components -- The ACE memory managementcomponents provide a flexible and extensible abstraction for managingdynamic allocation and deallocation of interprocess shared memory andintraprocess heap memory.
The C++ wrappers provide many of the same features as the OSadaptation layer in ACE. However, these features are structured interms of C++ classes and objects, rather than stand-alone C functions.This OO packaging helps to reduce the effort required to learn and useACE correctly.
For instance, the use of C++ improves application robustness becausethe C++ wrappers are strongly typed. Therefore, compilers can detecttype system violations at compile-time rather than at run-time. Incontrast, it is not possible to detect typesystem violations forC-level OS APIs, such as sockets or filesystem I/O, until run-time.
ACE employs a number of techniques to minimize or eliminateperformance overhead. For instance, ACE uses C++ inlining extensivelyto eliminate method call overhead that would otherwise be incurredfrom the additional typesafety and levels of abstraction provided byits OS adaptation layer and the C++ wrappers In addition, ACE avoidsthe use of virtual methods for performance-critical wrappers, such assend
/recv
methods for socket and file I/O.
Frameworks
ACE also contains a higher-level network programming framework thatintegrates and enhances the lower-level C++ wrapper facades. Thisframework supports the dynamic configuration of concurrent distributedservices into applications. The framework portion of ACE contains thefollowing components:
- Event demultiplexing components -- The ACEReactorand Proactorare extensible, object-oriented demultiplexers that dispatchapplication-specific handlers in response to various types ofI/O-based, timer-based, signal-based, and synchronization-basedevents.
- Service initialization components -- The ACE Acceptor andConnector components decouple the active and passiveinitialization roles, respectively, from application-specific tasksthat communication services perform once initialization is complete.
- Service configuration components -- The ACE ServiceConfigurator supports the configuration of applications whoseservices may be assembled dynamically at installation-time and/orrun-time.
- Hierarchically-layered stream components -- The ACE Streamscomponents simplify the development of communication softwareapplications, such as user-level protocol stacks, that are composed ofhierarchically-layered services.
- ORB adapter components -- ACE can be integrated seamlesslywith single-threaded and multi-threaded CORBAimplementations via its ORBadapters.
The ACE framework components facilitate the development ofcommunication software that can be updated and extended without theneed to modify, recompile, relink, or often restart runningapplications. This flexibility is achieved in ACE by combining (1)C++ language features, such as templates, inheritance, and dynamicbinding, (2) design patterns, such as Abstract Factory, Strategy, andService Configurator, and (3) OS mechanisms, such as explicit dynamiclinking and multi-threading.
Distributed Services and Components
In addition to its OS adaptation layer, C++ wrapper facades, andframework components, ACE provides a standard library of distributedservices that are packaged as self-contained components. Althoughthese service components are not strictly part of the ACE frameworklibrary, these service components play two roles in ACE:
- Factoring out reusable distributed application buildingblocks -- These service components provide reusableimplementations of common distributed application tasks such asnaming, event routing, logging, time synchronization, and networklocking.
- Demonstrating common use-cases of ACE components -- Thedistributed services also demonstrate how ACE components likeReactors, Service Configurators, Acceptors and Connectors, ActiveObjects, and IPC wrappers can be used effectively to develop flexible,efficient, and reliable communication software.
Higher-level Distributed Computing Middleware Components
Developing robust, extensible, and efficient communicationapplications is challenging, even when using a communication frameworklike ACE. In particular, developers must still master a number ofcomplex OS and communication concepts such as:
- Network addressing and service identification.
- Presentation conversions, such as encryption, compression,and network byte-ordering conversions between heterogeneousend-systems with alternative processor byte-orderings.
- Process and thread creation and synchronization.
- System call and library routine interfaces to local and remoteinterprocess communication (IPC) mechanisms.
It is possible to alleviate some of the complexity of developingcommunication applications by employing higher-level distributedcomputing middleware, such as CORBA, DCOM, or Java RMI. Higher-leveldistributed computing middleware resides between clients and serversand automates many tedious and error-prone aspects of distributedapplication development, including:
- Authentication, authorization, and data security.
- Service location and binding.
- Service registration and activation.
- Demultiplexing and dispatching in response to events.
- Implementing message framing atop bytestream-orientedcommunication protocols like TCP.
- Presentation conversion issues involving network byte-orderingand parameter marshaling.
To provide developers of communication software with these features,the following higher-level middleware applications are bundled withthe ACE release:
- The ACE ORB (TAO) -- TAO is areal-time implementation of CORBA built using the framework componentsand patterns provided by ACE. TAO contains the network interface, OS,communication protocol, and CORBA middleware components and features.TAO is based on the standard OMG CORBA reference model, with theenhancements designed to overcome the shortcomings of conventionalORBs for high-performance and real-time applications. TAO, like ACE,is freely available, opensource software.
- JAWS -- JAWS is ahigh-performance, adaptive Web server built using the frameworkcomponents and patterns provided by ACE. JAWS is structured as aframework of frameworks. The overall JAWS framework containsthe following components and frameworks: an Event Dispatcher,Concurrency Strategy, I/O Strategy, Protocol Pipeline, ProtocolHandlers, and Cached Virtual Filesystem. Each framework is structuredas a set of collaborating objects implemented by combining andextending components in ACE. JAW is also freely available,open-source software.