ACE自带的例子test_proactor在windows、solaris、linux下的表现

 
字体变小 字体变大

 

1、什么是ACE(略)

2、什么是Proactor(略)

3、例子:/ACE_wrappers/examples/Reactor/Proactor/test_proactor

3.1、运行环境

172.16.34.11winxp

172.16.33.34linux(版本略)

172.16.33.23solaris(版本略)

 

3.234.11作为服务器端,33.34作为客户端:

 

服务器端先启动:

D:/share/ace_server_code/ACE_wrappers5.4/examples/Reactor/Proactor>test_proactor -d c:/test.txt

 

客户端启动发送文件:

[jcwang@portal Proactor]$ ./test_proactor -h 172.16.34.11 -f README

(25795 | 1024) ACE_POSIX_AIOCB_Proactor::Max Number of AIOs=1024

handle_read_file called

********************

bytes_to_read = 8192

handle = 3

bytes_transfered = 2946

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 2946

handle = 4

bytes_transfered = 2946

act = 0

success = 1

completion_key = 0

error = 0

 

服务器端收到文件数据:

./test_proactor.cpp:122:Receiver::open called

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 44

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 44

handle = 1776

bytes_transfered = 44

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 512

handle = 1776

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 512

handle = 1776

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 512

handle = 1776

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 512

handle = 1776

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 512

handle = 1776

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 512

handle = 1796

bytes_transfered = 386

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_file called

********************

bytes_to_write = 386

handle = 1776

bytes_transfered = 386

act = 0

success = 1

completion_key = 0

error = 0

 

服务器成功收到文件:)

 

3.333.23作为服务器端,34.11作为客户端:

 

服务器端先启动:

$ ./test_proactor

(5907 | 1) ACE_POSIX_AIOCB_Proactor::Max Number of AIOs=1024

 

客户端启动发送:

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 512

handle = 1924

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_transmit_file called

********************

socket = 1924

file = 1804

bytes_to_write = 0

bytes_per_send = 0

flags = 0

bytes_transfered = 3032

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 512

handle = 1924

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 512

handle = 1924

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 512

handle = 1924

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 512

handle = 1924

bytes_transfered = 512

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_file called

********************

bytes_to_read = 512

handle = 1952

bytes_transfered = 384

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_write_stream called

********************

bytes_to_write = 384

handle = 1924

bytes_transfered = 384

act = 0

success = 1

completion_key = 0

error = 0

 

服务器端:

../../../../examples/Reactor/Proactor/test_proactor.cpp:85:Receiver::open called

 

客户端再次调用发送。服务器端:

handle_read_stream called

********************

bytes_to_read = 1024

handle = 6

bytes_transfered = 1024

act = 0

success = 1

completion_key = 0

error = 0

********************

handle_read_stream called

********************

bytes_to_read = 1024

handle = 6

bytes_transfered = 1024

act = 0

success = 1

completion_key = 0

error = 0

********************

../../../../examples/Reactor/Proactor/test_proactor.cpp:85:Receiver::open called

 

几次之后:

服务器端:

********************

../../../../examples/Reactor/Proactor/test_proactor.cpp:85:Receiver::open called

ACE_POSIX_AIOCB_Proactor::delete_result_aiocb_list

 number pending AIO=0

 

$ ls -all

total 1898

drwxrwxrwx   4 gchen    wap         1024 Feb 12 15:04 .

drwxrwxrwx   9 gchen    wap          512 Jan 12 11:23 ..

drwxrwxrwx   2 gchen    wap          512 Jan 12 15:17 .deps

drwxrwxrwx   2 gchen    wap          512 Jan 12 15:17 .libs

-rw-rw-rw-   1 gchen    wap        36761 Jan 12 11:23 Makefile

-rw-r--r--   1 jcwang   wap            0 Feb 12 16:39 output

 

Output0,文件没写入:(

 

3.433.34作为服务器端(略,因为不支持)

 

4、结论(仅根据现象)

Windowsproactor支持得不错,起码走完了流程,成功接收从linux发来的文件,并新建文件写入数据;solaris从屏显上看也异步接收了数据,创建了文件,但没写入(不知原因),最令人费解的是客户端发送几次后ACE_POSIX_AIOCB_Proactor::delete_result_aiocb_list

 number pending AIO=0,由此终止,再连:ACE_SOCK_Connector::connect: 由于目标机器积极拒绝,无法连接;linux不支持,作为服务器无反应。

 

5、应用背景

之前有个用proactor框架做的并发服务器已在windows上作为服务运行得不错,现想移植到linuxsolaris上,框架不变,仍用proactor。但从基本例程的运行来看,似乎还需进一步分析可行性,也期冀技术上被支持,资源难寻呀!找了个aceqq群,几十人尚无人帮助我,期待!

 

注:

pend

[pend]

vi.

悬而未决

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
### 回答1: 在Java中,网络IO的实现方式有BIO、NIO、AIO三种。 1. BIO(Blocking I/O) BIO是Java最早的一种网络IO实现方式。它通过阻塞式的方式来进行网络IO操作,即一个线程在进行IO操作时会一直阻塞,直到IO操作完成。这种方式的优点是编程简单易懂,但缺点是并发性能较差,不能满足高并发的需求。 2. NIO(Non-blocking I/O) NIO是Java在1.4版本中引入的一种新的网络IO实现方式。NIO的核心是Selector(选择器),它能够监控多个通道的状态,当某个通道有数据可读或可写时,Selector会通知相应的线程进行处理。NIO采用非阻塞式的方式进行IO操作,可以支持更高的并发性能。但是,NIO编程难度较大,需要掌握较多的概念和技巧。 3. AIO(Asynchronous I/O) AIO是Java在1.7版本中引入的一种新的网络IO实现方式。AIO采用异步的方式进行IO操作,即一个线程在进行IO操作时不需要一直阻塞,而是可以继续执行其他任务,当IO操作完成后再由系统通知线程进行处理。AIO可以支持更高的并发性能,并且编程模型比NIO更加简单。但是,AIO的兼容性不如NIO,需要在操作系统和JVM等多个方面进行支持。 ### 回答2: 在Java中,网络IO可以通过不同的方式实现,这些方式包括BIO(阻塞IO)、NIO(非阻塞IO)和AIO(异步IO)。 BIO是最早的实现方式,也是最简单直观的方式。它的特点是使用阻塞模式,即当一个线程在进行IO操作时,其他线程必须等待IO操作完成才能继续执行。在BIO中,每个连接都需要一个独立的线程来处理,这可能导致服务器资源浪费,无法满足高并发的需求。 NIO是在Java 1.4中引入的新IO模型,相较于BIO,它具有更高的并发处理能力。NIO使用了多路复用器(Selector)来管理多个连接,一个线程可以通过一个选择器同时处理多个连接的IO操作,从而避免了每个连接都需要一个独立线程的问题。 AIO是在Java 1.7中引入的新IO模型,也被称为NIO.2。AIO是基于事件和回调机制的,它的特点是IO操作后不需要对应的线程进行阻塞等待,而是通过回调方式来通知IO操作已经完成。AIO适合处理连接数较多且连接时间较长的场景,例如聊天服务器。 综上所述,BIO、NIO和AIO是Java中实现网络IO的三种方式。BIO适用于连接数较小的场景,NIO适用于连接数较多但连接时间较短的场景,而AIO适用于连接数较多且连接时间较长的场景。选择适合的IO模型能够提高服务器的并发处理能力和效率。 ### 回答3: JAVA中有三种主要的网络IO实现方式,分别是BIO(Blocking IO)、NIO(Non-blocking IO)和AIO(Asynchronous IO)。 BIO是JAVA IO最传统的模型,采用阻塞方式进行IO操作。在BIO模型中,每个连接都需要一个独立的线程来处理,当有大量的连接时,就需要大量线程,会导致性能下降。 NIO是JAVA IO的改进版本,引入了通道(Channel)和缓冲区(Buffer)的概念。NIO采用非阻塞方式进行IO操作,可以提高IO的效率。在NIO模型中,一个线程可以处理多个连接,通过选择器(Selector)来监听多个通道的事件,当有事件发生时,线程可以进行处理。 AIO是JAVA NIO的进一步改进,引入了异步通道(AsynchronousChannel)和回调机制。AIO采用异步方式进行IO操作,可以在IO操作完成之后再通知线程进行处理,而不需要线程一直等待IO操作完成。AIO适用于高并发的场景,可以大大提高系统的吞吐量和性能。 总结来说,BIO适用于连接数较少且业务处理较简单的场景;NIO适用于连接数较多但每个连接的并发处理量不大的场景;AIO适用于连接数较多且每个连接的并发处理量大的场景。选择合适的IO模型可以根据业务需求和实际场景进行选择,来提高系统的性能和并发能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值