`
amornio19840908
  • 浏览: 55764 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论
文章列表
这几天公司网站每当业务高峰的时候,就出现如下状况: 1)web服务器CPU负载30~50%左右。(状况正常) 2)Mysql数据库负载正常。 3)连接Redis的Jedis 2.5.2 + common.pool2,一直报can not get a resource。 Jedis Pool的配置是: timeout=2000 max_total=30 max_idle=5 max_wait=3000 查看redis的监控软件发现redis连接数居然是max_total的3,4倍。 原因分析,及解决方法 1)怀疑,使用jedis的代码没有把获得的资源还回到pool中。但查 ...
Socket服务端,用一个池对象来保存SocketServer接收到的socket链接。 实现过程中注意 接收客户端连接,只要客户端进行了连接,就会触发accept();从而建立连接。如下: socket=serverSocket.accept();  此时需要new Handler(socket)一个对象,并将 ...
编译安装PHP 所需的支持库 注:php在5.3.3以后的版本都已经集成了php-fpm tar zxvf libiconv-1.11.tar.gz cd libiconv-1.11/ ./configure --prefix=/usr/local make make install cd ../ tar zxvf freetype-2.3.5.tar.gz cd freetype-2.3.5/ ./configure make make install cd ../ tar zxvf libpng-1.2.20.tar.gz cd libpng-1.2. ...
添加mysql组,及mysql用户 sudo groupadd mysql sudo useradd -g mysql -s /usr/sbin/nologin mysql 到 mariadb.org 下载 mariadb-5.5.30.tar.gz 编译,安装 MariaDB tar -zxvf mariadb-5.5.30.tar.gz cd mariadb-5.5.30/ 安装cmake apt-get install cmake 用cmake命令编译MariaDB cmake . -DCMAKE_INSTALL_PREFIX=/opt/mariadb -DMYSQL_DATAD ...
同步socket例子 服务端 #include <ctime> #include <iostream> #include <string> #include <boost/asio.hpp> using namespace std; int main() { try { cout << "server start..." << endl; boost::asio::io_service ios; boost::asio::ip::tcp::acceptor ...
跟着 http://www.boost.org/doc/libs/1_53_0/doc/html/boost_asio/tutorial.html 学习asio。 编译的时候需要加上 -lboost_system 同步定时器例子 #include <iostream> #include <boost/asio.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace std; void tuttimer1() { boost::asio: ...
条件变量 如果线程之间执行顺序上有依赖关系,可使用条件变量(Condition variables)。 可以到boost官网中参考条件变量(Condition variables)的使用。 条件变量必须和互斥量配合使用,等待另一个线程重某个事件的发生(满足某个条件),然后线程才能继续执行。 共有两种条件变量对象condition_variable, condition_variable_any,一般情况下使用condition_variable_any。 条件变量的使用方式: 拥有条件变量的线程先锁定互斥量,然后循环检查某个条件,如果条件不满足,那么就调用条件变量的成员函数wait() ...
线程同步 虽然多线程的使用可以提高应用程序的性能,但也增加了复杂性。如果使用线程在同一时间执行几个函数,访问共享资源时必须相应地同步。 Boost.Thread提供多个的互斥类。 boost::mutex是最简单的一个,它的使用就像linux下的二进制互斥量。互斥的基本原则是当一个特定的线程拥有资源的时候防止其他线程夺取其所有权,一旦释放,其他的线程可以取得所有权。这将导致线程等待至另一个线程完成处理一些操作,从而相应地释放互斥对象的所有权。 下面的示例使用一个类型为 boost::mutex 的simple_mutex全局互斥对象。thread()函数获取此对象的所有权才在 for 循 ...
线程中断 在一个线程对象上调用 interrupt() 会中断相应的线程,并会在这个线程中抛出一个类型为 boost::thread_interrupted 的异常。 如果给定的线程不包含任何中断点,简单调用interrupt就不会起作用。 每当一个线程中断点,它就会检查interrupt是否被调用过。只有被调用过了, boost::thread_interrupted 异常才会相应地抛出。 Boost.Thread定义了一系列的中断点,例如sleep() 函数,由于sleep() 在这个例子里被调用了五次,该线程就检查了五次它是否应该被中断。然而sleep()之间的调用,却不能使线程中断 ...
使用boost.thread的时候,记得link到项目中,否则会报找不到的错误。 下面是使用mutex锁的例子 #include <boost/thread.hpp> #include <boost/thread/mutex.hpp> #include <iostream> boost::mutex io_mutex; using namespace std; // 可以试试,将wait(int) 放在不同位置产生的效果 void wait(int seconds) { boost::this_thread::s ...
Varnish的安装依赖pcre 下载获得最新版本的pcre 安装pcre > tar -xjvf pcre-8.32.tar.bz2 > cd pcre-8.32 > ./configure --prefix=/usr/local/pcre/ > make && make install 为Varnish准备目录 > mkdir data > mkdir data/varnish > mkdir data/varnish/cache > mkdir data/varnish/log 下载Varnis ...
Web Bench的安装依赖于ctags 首先安装 ctags > wget http://prdownloads.sourceforge.net/ctags/ctags-5.8.tar.gz > tar zxvf ctags-5.8.tar.gz > cd ctags-5.8 > ./configure > make && make install 再安装Web Bench > wget http://www.linuxidc.com/system/systembak/webbench/webbench-1.5.t ...
下载log4erl https://github.com/ahmednawras/log4erl 我是使用README.txt上的svn下载的 $> svn checkout http://log4erl.googlecode.com/svn/trunk/ log4erl $> cd log4erl $> make 编译成功。 新建一个测试项目test 新建module,test_log,代码如下 -module(test_log). -export([init/0,log/0]). init()-> init_log4erl(). log ...
C++ 日志配置 项目路径 /workspace/community_service 项目目录 -src --community_cpp.cpp --log.h log.h 定义了日志级别,及写日志等方法 初始化日志文件 community_cpp.cpp的main方法中初始化日志文件 try { // 定义的日志文件,位于项目的根目录下。 FILE* pFile = fopen("community_service.log", "a"); Output2FILE::Stream() = pFile; ...
C++ 读取配置文件 项目路径 /workspace/community_service 项目目录 -src --config.h --config.cpp --community_cpp.cpp --systemInit.h --systemInit.cpp -thrift -thrift_cpp community_service.conf community_service.conf 中定义了一些需要配置的字段,例如:communityPort=10020 systemInit.h和systemInit.cpp, 1)定义了在c++中,对应于community_servi ...
Global site tag (gtag.js) - Google Analytics