免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: fiendcly
打印 上一主题 下一主题

[C++] boost asio 壓力測試六小時後 Killed 的原因? [复制链接]

论坛徽章:
0
11 [报告]
发表于 2012-08-24 19:42 |只看该作者
hellioncu 发表于 2012-08-24 09:02
这么晚还干活


是啊~在趕工......

快做完了.

現在不停的測穩定性 ^^

论坛徽章:
2
CU大牛徽章
日期:2013-04-17 11:46:28CU大牛徽章
日期:2013-04-17 11:46:39
12 [报告]
发表于 2012-08-26 00:37 |只看该作者
测试代码呢?

论坛徽章:
0
13 [报告]
发表于 2012-08-26 02:43 |只看该作者
本帖最后由 fiendcly 于 2012-08-26 02:57 编辑
cdtits 发表于 2012-08-26 00:37
测试代码呢?



我中間有將它跟 php-fpm 接起來 使用 fastcgi.h 跟 PHP-FPM 接起來.

CLIENT 端 直接寫支~SOCKET 程式 不停的 FORK 新的 PROCESS ~

在連線後 ,  丟 一億個 WRITE OR SEND 進去.
  1. /*
  2. * fastcgi.h --
  3. *
  4. *        Defines for the FastCGI protocol.
  5. *
  6. *
  7. * Copyright (c) 1995-1996 Open Market, Inc.
  8. *
  9. * See the file "LICENSE.TERMS" for information on usage and redistribution
  10. * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. *
  12. * $Id: fastcgi.h,v 1.1.1.1 1997/09/16 15:36:32 stanleyg Exp $
  13. */

  14. #ifndef _FASTCGI_H
  15. #define _FASTCGI_H

  16. /*
  17. * Listening socket file number
  18. */
  19. #define FCGI_LISTENSOCK_FILENO 0

  20. typedef struct {
  21.     unsigned char version;
  22.     unsigned char type;
  23.     unsigned char requestIdB1;
  24.     unsigned char requestIdB0;
  25.     unsigned char contentLengthB1;
  26.     unsigned char contentLengthB0;
  27.     unsigned char paddingLength;
  28.     unsigned char reserved;
  29. } FCGI_Header;

  30. #define FCGI_MAX_LENGTH 0xffff

  31. /*
  32. * Number of bytes in a FCGI_Header.  Future versions of the protocol
  33. * will not reduce this number.
  34. */
  35. #define FCGI_HEADER_LEN  8

  36. /*
  37. * Value for version component of FCGI_Header
  38. */
  39. #define FCGI_VERSION_1           1

  40. /*
  41. * Values for type component of FCGI_Header
  42. */
  43. #define FCGI_BEGIN_REQUEST       1
  44. #define FCGI_ABORT_REQUEST       2
  45. #define FCGI_END_REQUEST         3
  46. #define FCGI_PARAMS              4
  47. #define FCGI_STDIN               5
  48. #define FCGI_STDOUT              6
  49. #define FCGI_STDERR              7
  50. #define FCGI_DATA                8
  51. #define FCGI_GET_VALUES          9
  52. #define FCGI_GET_VALUES_RESULT  10
  53. #define FCGI_UNKNOWN_TYPE       11
  54. #define FCGI_MAXTYPE (FCGI_UNKNOWN_TYPE)

  55. /*
  56. * Value for requestId component of FCGI_Header
  57. */
  58. #define FCGI_NULL_REQUEST_ID     0


  59. typedef struct {
  60.     unsigned char roleB1;
  61.     unsigned char roleB0;
  62.     unsigned char flags;
  63.     unsigned char reserved[5];
  64. } FCGI_BeginRequestBody;

  65. typedef struct {
  66.     FCGI_Header header;
  67.     FCGI_BeginRequestBody body;
  68. } FCGI_BeginRequestRecord;

  69. /*
  70. * Mask for flags component of FCGI_BeginRequestBody
  71. */
  72. #define FCGI_KEEP_CONN  1

  73. /*
  74. * Values for role component of FCGI_BeginRequestBody
  75. */
  76. #define FCGI_RESPONDER  1
  77. #define FCGI_AUTHORIZER 2
  78. #define FCGI_FILTER     3


  79. typedef struct {
  80.     unsigned char appStatusB3;
  81.     unsigned char appStatusB2;
  82.     unsigned char appStatusB1;
  83.     unsigned char appStatusB0;
  84.     unsigned char protocolStatus;
  85.     unsigned char reserved[3];
  86. } FCGI_EndRequestBody;

  87. typedef struct {
  88.     FCGI_Header header;
  89.     FCGI_EndRequestBody body;
  90. } FCGI_EndRequestRecord;

  91. /*
  92. * Values for protocolStatus component of FCGI_EndRequestBody
  93. */
  94. #define FCGI_REQUEST_COMPLETE 0
  95. #define FCGI_CANT_MPX_CONN    1
  96. #define FCGI_OVERLOADED       2
  97. #define FCGI_UNKNOWN_ROLE     3


  98. /*
  99. * Variable names for FCGI_GET_VALUES / FCGI_GET_VALUES_RESULT records
  100. */
  101. #define FCGI_MAX_CONNS  "FCGI_MAX_CONNS"
  102. #define FCGI_MAX_REQS   "FCGI_MAX_REQS"
  103. #define FCGI_MPXS_CONNS "FCGI_MPXS_CONNS"


  104. typedef struct {
  105.     unsigned char type;   
  106.     unsigned char reserved[7];
  107. } FCGI_UnknownTypeBody;

  108. typedef struct {
  109.     FCGI_Header header;
  110.     FCGI_UnknownTypeBody body;
  111. } FCGI_UnknownTypeRecord;

  112. #endif        /* _FASTCGI_H */
复制代码
http://www.boost.org/
BOOST 裡有 範例程式.
http://www.boost.org/doc/libs/1_ ... _asio/examples.html

用 異步 IO 的 ECHO SERVER.
  1. //
  2. // async_tcp_echo_server.cpp
  3. // ~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //
  5. // Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com)
  6. //
  7. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  8. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. //

  10. #include <cstdlib>
  11. #include <iostream>
  12. #include <boost/bind.hpp>
  13. #include <boost/asio.hpp>

  14. using boost::asio::ip::tcp;

  15. class session
  16. {
  17. public:
  18.   session(boost::asio::io_service& io_service)
  19.     : socket_(io_service)
  20.   {
  21.   }

  22.   tcp::socket& socket()
  23.   {
  24.     return socket_;
  25.   }

  26.   void start()
  27.   {
  28.     socket_.async_read_some(boost::asio::buffer(data_, max_length),
  29.         boost::bind(&session::handle_read, this,
  30.           boost::asio::placeholders::error,
  31.           boost::asio::placeholders::bytes_transferred));
  32.   }

  33. private:
  34.   void handle_read(const boost::system::error_code& error,
  35.       size_t bytes_transferred)
  36.   {
  37.     if (!error)
  38.     {
  39.       boost::asio::async_write(socket_,
  40.           boost::asio::buffer(data_, bytes_transferred),
  41.           boost::bind(&session::handle_write, this,
  42.             boost::asio::placeholders::error));
  43.     }
  44.     else
  45.     {
  46.       delete this;
  47.     }
  48.   }

  49.   void handle_write(const boost::system::error_code& error)
  50.   {
  51.     if (!error)
  52.     {
  53.       socket_.async_read_some(boost::asio::buffer(data_, max_length),
  54.           boost::bind(&session::handle_read, this,
  55.             boost::asio::placeholders::error,
  56.             boost::asio::placeholders::bytes_transferred));
  57.     }
  58.     else
  59.     {
  60.       delete this;
  61.     }
  62.   }

  63.   tcp::socket socket_;
  64.   enum { max_length = 1024 };
  65.   char data_[max_length];
  66. };

  67. class server
  68. {
  69. public:
  70.   server(boost::asio::io_service& io_service, short port)
  71.     : io_service_(io_service),
  72.       acceptor_(io_service, tcp::endpoint(tcp::v4(), port))
  73.   {
  74.     start_accept();
  75.   }

  76. private:
  77.   void start_accept()
  78.   {
  79.     session* new_session = new session(io_service_);
  80.     acceptor_.async_accept(new_session->socket(),
  81.         boost::bind(&server::handle_accept, this, new_session,
  82.           boost::asio::placeholders::error));
  83.   }

  84.   void handle_accept(session* new_session,
  85.       const boost::system::error_code& error)
  86.   {
  87.     if (!error)
  88.     {
  89.       new_session->start();
  90.     }
  91.     else
  92.     {
  93.       delete new_session;
  94.     }

  95.     start_accept();
  96.   }

  97.   boost::asio::io_service& io_service_;
  98.   tcp::acceptor acceptor_;
  99. };

  100. int main(int argc, char* argv[])
  101. {
  102.   try
  103.   {
  104.     if (argc != 2)
  105.     {
  106.       std::cerr << "Usage: async_tcp_echo_server <port>\n";
  107.       return 1;
  108.     }

  109.     boost::asio::io_service io_service;

  110.     using namespace std; // For atoi.
  111.     server s(io_service, atoi(argv[1]));

  112.     io_service.run();
  113.   }
  114.   catch (std::exception& e)
  115.   {
  116.     std::cerr << "Exception: " << e.what() << "\n";
  117.   }

  118.   return 0;
  119. }
复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP