天天看點

boost asio 性能與線程安全性

http://stackoverflow.com/questions/12794107/why-do-i-need-strand-per-connection-when-using-boostasio/12801042

http://www.boost.org/doc/libs/1_51_0/doc/html/boost_asio/overview/core/strands.html

url1:  同一個socket上, 不能 read write讀寫不能并發。。。。 !!!!???? 這個感覺不可能吧。。。那也太弱智了。。

====确實不能對同一個socket同時讀寫,socket能封裝了basic_socket_stream, 該類的對象不能支援同時進行讀寫操作。ps, fstream也不能支援同時讀寫吧。。

http://stackoverflow.com/questions/4078484/using-boost-sockets-do-i-need-only-one-io-service

隻強調, 不能 對同一個socket同時多讀, 或者同時多寫。

http://stackoverflow.com/questions/6161725/boostasio-threadpool-vs-io-service-per-cpu-design

性能遞升。。。

  1. single thread and a single 

    io_service

  2. multiple threads, each invoking 

    io_service::run()

     from a single 

    io_service

    . Use strands for handlers that require access to shared data structures.
  3. io_service

     per cpu

http://en.highscore.de/cpp/boost/asio.html#asio_networkprogramming

high score boost裡面有boost asio的用法

1) single thread && single io_service, 最簡單, 性能最一般

2) multithread && single io_service

3) io_service per thread.  multi io_service.

這三個性能應該也是遞增的。。。

http://stackoverflow.com/questions/11010530/do-we-need-multiple-io-service-per-thread-for-threaded-boostasio-server-with/11011080#11011080

single thread && single io_service性能肯定是不夠的。

boost asio example

HTTP Server 2

An HTTP server using an io_service-per-CPU design.

HTTP Server 3

An HTTP server using a single io_service and a thread pool calling 

io_service::run()

.

http://stackoverflow.com/questions/8557067/thread-safe-coroutines-with-asio

http://www.crystalclearsoftware.com/soc/coroutine/coroutine/coroutine_thread.html

coroutine能使異步切碎的邏輯看起來像同步的方式寫代碼。

但是coroutine不能支援多線程, 隻能一個ioservice一個線程的方式。