port 22 <- 이부분을 찾아서 수정하면 된다. ex) port 8025
주석이 되어 있다면(#port 22) 주석제거하면 됨.
서비스 재시작~
/etc/init.d/sshd restart
#define MAX_MESSAGE_NUMBER 100 #define MAX_MESSAGE_SIZE 128 #define MAX_PROCESS_NAME 32 #include <boost/interprocess/ipc/message_queue.hpp> #include <boost/interprocess/creation_tags.hpp> #include <iostream> using namespace boost::interprocess; class CMessageQ { public: CMessageQ(const char* pName) { m_pMsgQ = NULL; strcpy(m_Name, pName); } ~CMessageQ(void) { Remove(); } public: bool Create() { try{ Remove(); // 메모리에서 제거되면 안되므로 static으로 선언 static message_queue mq(create_only, m_Name, MAX_MESSAGE_NUMBER, MAX_MESSAGE_SIZE); m_pMsgQ = &mq; }catch(interprocess_exception &ex){ std::cout << "MessageQ Create() error : " << ex.what() << std::endl; return false; } return true; } bool Open() { try{ static message_queue mq(open_only, m_Name); m_pMsgQ = &mq; }catch(interprocess_exception &ex){ std::cout << "MessageQ Open() error : " << ex.what() << std::endl; return false; } return true; } size_t Get() { size_t temp; try{ temp = m_pMsgQ->get_num_msg(); return temp; }catch(interprocess_exception &ex){ std::cout << "MessageQ Get() error : " << ex.what() << std::endl; } return 0; } template <typename T> bool Send(T* Data,size_t Size, unsigned int priority = 0) { try{ m_pMsgQ->send(Data, Size, priority); }catch(interprocess_exception &ex){ std::cout << "MessageQ Send() error : " << ex.what() << std::endl; return false; } return true; } template <typename T> bool Recv(T* Data, size_t Size, unsigned int& priority) { size_t recvd_size=0; try{ //m_pMsgQ->receive(Data, Size, recvd_size, priority); m_pMsgQ->receive(Data, MAX_MESSAGE_SIZE, recvd_size, priority); if( Size != recvd_size ) { std::cout << "MessageQ Recv() Size Wrong : " << std::endl; return false; } }catch(interprocess_exception &ex){ std::cout << "MessageQ Recv() error : " << ex.what() << std::endl; return false; } return true; } void Remove() { message_queue::remove(m_Name); } private: char m_Name[MAX_PROCESS_NAME]; // 프로세스 이름 message_queue* m_pMsgQ; // 메시지큐 포인터 };
원문 :
http://www.boost.org/doc/libs/1_40_0/doc/html/interprocess/synchronization_mechanisms.html#interprocess.synchronization_mechanisms.message_queue
메시지큐란 무엇인가?
메시지큐는 메시지들의 목록과 유사하다. 스레드들은 메시지들을 큐에 넣을 수 있고 큐로 부터 제거할 수도 있다. 각각의 메시지들은 또한 우선순위가 낮은 메시지들보다 먼저 수행될 수 있는 높은 우선순위와 같은 우선순위를 가진다. 각각의 메시지들은 몇가지의 특성을 가지고 있다.
스레드는 아래의 3가지 방법을 통해 메시지를 보내거나 받을 수 있다.
메시지큐는 단지 프로세스들 사이에 raw bytes를 복사하고 개체(object)를 전송하지는 않는다. 이것은 만약 우리가 메시지큐를 이용하여 개체(object)를 전송하고 싶다면, 그 개체는 반드시 binary serializable 되어야 한다. 예를 들면, 우리는 프로세스들 사이에 정수(integer)를 전송할 수 있지만 std::string은 전송 할 수 없다. 이때는 Boost.Serialization 또는 Boost.Interprocess 라는 향상된 메커니즘을 사용해서 프로세스들 사이에 복합적인 데이터(complex data)를 전송해야 한다.
Boost.Interprocess 메시지큐는 프로세스간 통신이라고 불린다. 메시지큐는 이름을 사용해서 만들어지고 파일처럼 이름으로 불러온다. 메시지큐를 생성할 때, 사용자는 반드시 메시지의 최대 사이즈와 메시지큐를 저장할 수 있는 최대 메시지 수를 정의하여야 한다. 이러한 파라미터들은 리소스들을 정의 할 것이다.(한 예로, 공유메모리가 사용되고 있다면, 공유메모리(shared memory)의 크기는 메시지큐에 제공된다)
using boost::interprocess; //Create a message_queue. If the queue //exists throws an exception message_queue mq (create_only //생성 전용(only create) ,"message_queue" //이름 ,100 //최대 메시지 수(max message number) ,100 //최대 메시지 크기(max message size) );
using boost::interprocess; //Creates or opens a message_queue. If the queue //does not exist creates it, otherwise opens it. //Message number and size are ignored if the queue //is opened message_queue mq (open_or_create //읽기 또는 생성(open or create) ,"message_queue" //이름(name) ,100 //최대 메시지 수(max message number) ,100 //최대 메시지 크기(max message size) );
using boost::interprocess; //Opens a message_queue. If the queue //does not exist throws an exception. message_queue mq (open_only //읽기전용(only open) ,"message_queue" //이름(name) );
using boost::interprocess; message_queue::remove("message_queue");
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/interprocess/ipc/message_queue.hpp> #include <iostream> #include <vector> using namespace boost::interprocess; int main () { try{ //Erase previous message queue message_queue::remove("message_queue"); //Create a message_queue. message_queue mq (create_only //only create ,"message_queue" //name ,100 //max message number ,sizeof(int) //max message size ); //Send 100 numbers for(int i = 0; i < 100; ++i){ mq.send(&i, sizeof(i), 0); } } catch(interprocess_exception &ex){ std::cout << ex.what() << std::endl; return 1; } return 0; }
#include <boost/interprocess/ipc/message_queue.hpp> #include <iostream> #include <vector> using namespace boost::interprocess; int main () { try{ //Open a message queue. message_queue mq (open_only //only create ,"message_queue" //name ); unsigned int priority; std::size_t recvd_size; //Receive 100 numbers for(int i = 0; i < 100; ++i){ int number; mq.receive(&number, sizeof(number), recvd_size, priority); if(number != i || recvd_size != sizeof(number)) return 1; } } catch(interprocess_exception &ex){ message_queue::remove("message_queue"); std::cout << ex.what() << std::endl; return 1; } message_queue::remove("message_queue"); return 0; }
영어의 Transaction은 거래를 뜻한다. 예를 들어 돈을 주었는데 물건을 받지 못한다면, 그 거래는 이루어지지 못하고 원상태로 복구되어야 한다. 이와 같이 쪼갤 수 없는 하나의 처리 행위를 원자적 행위라 고 한다. 여기서 쪼갤 수 없다는 말의 의미는 실제로 쪼갤 수 없다기보다는 만일 쪼개질 경우 시스템에 심각한 오류를 초래할 수 있다는 것이다. 이러한 개념의 기능을 ATM 또는 데이터베이스 등의 시스템에서 제공하는 것이 바로 트랜잭션이다.
트랜잭션은 사용자가 시스템에 요구를 시작하여 시스템 내의 처리, 시스템에서 사용자에게 응답하는 모든 처리를 포함한다. 이러한 트랜잭션이 충족해야 하는 기술적인 요건은 ACID가 있다.
출처 : 위키백과
http://ko.wikipedia.org/wiki/%ED%8A%B8%EB%9E%9C%EC%9E%AD%EC%85%98
void dGet_value2(void* *p2) { printf("&p2:0x%04x\n", &p2); printf("p2:0x%04x\n", p2); printf("*p2:0x%04x\n", *p2); printf("\n"); static int value = 5; *p2 = &value; } void dGet_value1(int* *p1) { printf("&p1:0x%04x\n", &p1); printf("p1:0x%04x\n", p1); printf("*p1:0x%04x\n", *p1); printf("\n"); dGet_value2((void **)&(*p1)); } int _tmain(int argc, _TCHAR* argv[]) { int* pmain; printf("&pmain:0x%04x\n", &pmain); printf("pmain:0x%04x\n", pmain); printf("\n"); dGet_value1(&pmain); printf("pmain-> %d\n",*pmain); return 0; }
하나씩 설치하다가 잘안되서...
깔끔하게 APM_Setup 으로 설치하였다 ~! (XP환경)
[InnoDB]
1. InnoDB가 사용가능한지 확인해본다.
mysql> show variables like 'have_innodb';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_innodb | YES |
+---------------+-------+
1 row in set (0.00 sec)
!!! 여기서 Value에 Disable라고 뜬다면, my.ini를 열어서...
# BDB타입을 사용할지 하지 않을지
#skip-bdb <- 이부분 앞에 #으로 바꿔주고 mysql 재시작 하면 된다 ~
2. 설정 상태 확인한다.
mysql> show status like '%innodb%';
+-----------------------------------+---------+
| Variable_name | Value |
+-----------------------------------+---------+
| Com_show_innodb_status | 0 |
| Innodb_buffer_pool_pages_data | 19 |
| Innodb_buffer_pool_pages_dirty | 0 |
| Innodb_buffer_pool_pages_flushed | 0 |
| Innodb_buffer_pool_pages_free | 493 |
| Innodb_buffer_pool_pages_misc | 0 |
| Innodb_buffer_pool_pages_total | 512 |
| Innodb_buffer_pool_read_ahead_rnd | 1 |
| Innodb_buffer_pool_read_ahead_seq | 0 |
| Innodb_buffer_pool_read_requests | 77 |
| Innodb_buffer_pool_reads | 12 |
| Innodb_buffer_pool_wait_free | 0 |
| Innodb_buffer_pool_write_requests | 0 |
| Innodb_data_fsyncs | 3 |
| Innodb_data_pending_fsyncs | 0 |
| Innodb_data_pending_reads | 0 |
| Innodb_data_pending_writes | 0 |
| Innodb_data_read | 2494464 |
| Innodb_data_reads | 29 |
| Innodb_data_writes | 3 |
| Innodb_data_written | 1536 |
| Innodb_dblwr_pages_written | 0 |
| Innodb_dblwr_writes | 0 |
| Innodb_log_waits | 0 |
| Innodb_log_write_requests | 0 |
| Innodb_log_writes | 1 |
| Innodb_os_log_fsyncs | 3 |
| Innodb_os_log_pending_fsyncs | 0 |
| Innodb_os_log_pending_writes | 0 |
| Innodb_os_log_written | 512 |
| Innodb_page_size | 16384 |
| Innodb_pages_created | 0 |
| Innodb_pages_read | 19 |
| Innodb_pages_written | 0 |
| Innodb_row_lock_current_waits | 0 |
| Innodb_row_lock_time | 0 |
| Innodb_row_lock_time_avg | 0 |
| Innodb_row_lock_time_max | 0 |
| Innodb_row_lock_waits | 0 |
| Innodb_rows_deleted | 0 |
| Innodb_rows_inserted | 0 |
| Innodb_rows_read | 0 |
| Innodb_rows_updated | 0 |
+-----------------------------------+---------+
43 rows in set (0.00 sec)
Value에 설정된 값은 아마 my-innodb-heavy-4G.ini 를 편집하면 바뀔것 같다.
지금은 그냥 해보는게 중요해서..ㅎㅎ 건너뜀 ~ㅎ
3. 기존의 테이블 엔진 바꾸기
먼저 테이블 속성을 보자 ~
mysql> use testdb;
mysql> show table status where name='inno_test';
+-----------+--------+---------+------------+------+----------------+-----------
--+-------------------+--------------+-----------+----------------+-------------
--------+---------------------+------------+-----------------+----------+-------
---------+---------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_lengt
h | Max_data_length | Index_length | Data_free | Auto_increment | Create_time
| Update_time | Check_time | Collation | Checksum | Create
_options | Comment |
+-----------+--------+---------+------------+------+----------------+-----------
--+-------------------+--------------+-----------+----------------+-------------
--------+---------------------+------------+-----------------+----------+-------
---------+---------+
| inno_test | MyISAM | 10 | Fixed | 1 | 65 | 6
5 | 18295873486192639 | 2048 | 0 | NULL | 2009-11-20 1
5:20:35 | 2009-11-20 15:24:25 | NULL | utf8_general_ci | NULL |
| |
+-----------+--------+---------+------------+------+----------------+-----------
--+-------------------+--------------+-----------+----------------+-------------
--------+---------------------+------------+-----------------+----------+-------
---------+---------+
1 row in set (0.00 sec)
MyISAM 엔진이다. 이제 InnoDB로 변경 !!!
mysql> alter table inno_test type=innodb;
Query OK, 1 row affected, 1 warning (0.11 sec)
레코드: 1개 중복: 0개 경고: 0개
mysql> show table status where name='inno_test';
+-----------+--------+---------+------------+------+----------------+-----------
--+-----------------+--------------+-----------+----------------+---------------
------+-------------+------------+-----------------+----------+----------------+
----------------------+
| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_lengt
h | Max_data_length | Index_length | Data_free | Auto_increment | Create_time
| Update_time | Check_time | Collation | Checksum | Create_options |
Comment |
+-----------+--------+---------+------------+------+----------------+-----------
--+-----------------+--------------+-----------+----------------+---------------
------+-------------+------------+-----------------+----------+----------------+
----------------------+
| inno_test | InnoDB | 10 | Compact | 1 | 16384 | 1638
4 | 0 | 16384 | 0 | NULL | 2009-11-20 15:
20:35 | NULL | NULL | utf8_general_ci | NULL | |
InnoDB free: 4096 kB |
+-----------+--------+---------+------------+------+----------------+-----------
--+-----------------+--------------+-----------+----------------+---------------
------+-------------+------------+-----------------+----------+----------------+
----------------------+
1 row in set (0.00 sec)
InnoDB로 변경이 되었다 ~
4. 트랜잭션. rollback, commit 해보기
mysql> select * from inno_test;
+------+------+
| a | b |
+------+------+
| 2 | cho |
+------+------+
1 row in set (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> update inno_test set a=3;
Query OK, 1 row affected (0.00 sec)
일치하는 Rows : 1개 변경됨: 1개 경고: 0개
mysql> select * from inno_test;
+------+------+
| a | b |
+------+------+
| 3 | cho |
+------+------+
1 row in set (0.00 sec)
mysql> rollback;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from inno_test;
+------+------+
| a | b |
+------+------+
| 2 | cho |
+------+------+
1 row in set (0.00 sec)
업데이트 쿼리를 하기전에 begin;을 입력하고 쿼리를 수행하면,
실제 데이터가 바로 바뀌지 않는다.
commit; 이 들어오면 실제로 바뀌게 되고 rollback;이 들어오면 적용하지 않게 된다.
이제는 commit;을 해보자.
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> update inno_test set a=3;
Query OK, 1 row affected (0.00 sec)
일치하는 Rows : 1개 변경됨: 1개 경고: 0개
mysql> select * from inno_test;
+------+------+
| a | b |
+------+------+
| 3 | cho |
+------+------+
1 row in set (0.00 sec)
mysql> commit;
Query OK, 0 rows affected (0.03 sec)
mysql> select * from inno_test;
+------+------+
| a | b |
+------+------+
| 3 | cho |
+------+------+
1 row in set (0.00 sec)
적용이 되었다 ~
트랜잭션에 대해서 좀 더 공부해야겠다 ~~~!