ä»æ¥ãç§ã¯ç¯ããééããä¿®æ£ããããšæããŸãã æè¡çãªè©³çŽ°ã«æ倧éã®æ³šæãæããªãããSNMPç£èŠããŒã¿ãåŠçããå®éã®ã¿ã¹ã¯ã«ã€ããŠèª¬æããŸãã ãœãªã¥ãŒã·ã§ã³ã®ã¢ãããŒãã®éžæãæ£åœåããããã©ãŒãã³ã¹ãæ¯èŒããããšããŸãã ãŸããåå¿è ã«åé¡ãåŒãèµ·ããå¯èœæ§ã®ããæè¡çãªãã€ã³ãã«ã泚æãæããŸãã å ã«é²ãåã« ã DenKrep ã xlix123 ã zhekappp ãããã³åã®èšäºã®è°è«ã§ä¿¡ããããªãã»ã©ã®æçšãªã¢ããã€ã¹ãããŠãããä»ã®ãã¹ãŠã®ä»²éã«æè¬ããããšæããŸãã
ããã¯äœã®ããã§ããïŒ
次ã®ãããªè³ªåã«ã¯ãŸã£ããèå³ããªããšããã«èšãããã§ãã
- Oracleã«ããŒã¿ãã¢ããããŒãã§ããæ倧é床ã¯ïŒ
- OracleãPostgreSQLããéãã®ã¯äœã§ããïŒ
- ããŒã¿ããŒã¹ããŒãã«ã«æ¿å ¥ã§ããé床ã¯ã©ããããã§ããïŒ
ã»ãšãã©ã®å Žåããããã®è³ªåãªã©ã¯æå³ããããŸããïŒå°ãªããšãããŒããŠã§ã¢æ§æã®è©³çŽ°ããåé¢ãããŠããå ŽåïŒã ç§ã¯ãOracleãµãŒããŒãã©ã®ããŒããŠã§ã¢ã§å®è¡ãããŠãããã«ã€ããŠãæå³çã«èªããŸããã ç§ã®æèŠã§ã¯ãããã¯éèŠã§ã¯ãããŸããã ããããäœãéèŠãªã®ã§ããããïŒ
ããšãã°ãSNMPç£èŠããŒã¿ã®åéãªã©ã®å®éã®ã¿ã¹ã¯ãããããšãéèŠã§ããããã®å®è¡äžã«ãåŠçãå¿ èŠãªå€§éã®ããŒã¿ã絶ããçæãããŸãã ãã®å Žåã次ã®ç¹ãéèŠã§ãã
- ããŒã¿ãããŒãã«ã«æ¿å ¥ããã ãã§ã¯ååã§ã¯ãããŸããïŒããŒã¿ã®æ£ç¢ºãªåŠçæ¹æ³ãšçç±ã次ã®ã»ã¯ã·ã§ã³ã§èª¬æããŸãïŒ
- ããŒã¿ããŒã¹ãµãŒããŒäžã§ããŒã¿ã¯çæãããŸããïŒãããããåäžã®ããŒã¿ããŒã¹ã«ããŒã¿ã転éããè€æ°ã®ããŒã¿åéãµãŒããŒãååšããŸãïŒ
- ããŒã¿ã¯ç¶ç¶çã«åä¿¡ãããåžžã«åŠçãããå¿ èŠããããããããŒã¿ã®åŠçæéãæå°éã«æããããšãæãŸããïŒç·æ¥äºæ ã®çºçã«å¯Ÿããæå°å¿çæéã確ä¿ããããïŒ
- ããŒã¿ã®äžéšã®æ倱ã¯èš±å¯ãããŠããŸãïŒäºæ ãçºçããå ŽåãçŸåšã®ããŒã¿ã®äžéšã倱ãããå Žåã§ãã次ã®ããŒãªã³ã°ãµã€ã¯ã«ã§ãããèŠã€ããŸãïŒ
- äž»èŠãªãã©ã¡ãŒã¿ãŒã®å€æŽå±¥æŽã¯ãé·æéç¶æããå¿ èŠããããŸã
ãã®åé¡ã解決ããããã®ããŸããŸãªãªãã·ã§ã³ãæ€èšãããããã®ããã©ãŒãã³ã¹ãæ¯èŒããŸãã ãã¡ãããç®æšã¯æãçç£çãªãœãªã¥ãŒã·ã§ã³ãèŠã€ããããšã§ãã
åé¡ã®å£°æ
ãŸããSNMPã䜿çšããŠååŸããããŒã¿ã®çš®é¡ãèŠããŠããŸããïŒ å®éãGETãªã¯ãšã¹ãã䜿çšããŠå¯Ÿè±¡ã®OIDãç §äŒããããšã«ãããããã€ãã®äºåå®çŸ©å€æ°ã®å€ãååŸã§ããŸãã ããšãã°ãOID = 1.3.6.1.2.1.1.3.0ããªã¯ãšã¹ããããšãç£èŠã®ããã«sysUpTimeãšåããããéèŠãªå€ãååŸã§ããŸãã SNMPãä»ããŠã¢ã¯ã»ã¹ãããå€æ°ã®å€ã¯ãå¿ ãããæ°å€ã§ã¯ãããŸããã æååã§ãããŸããŸããã
ãã ããSNMPã¯äžé£ã®ã¹ã«ã©ãŒå€æ°ãžã®ã¢ã¯ã»ã¹ã«éå®ãããŸããã å€æ°ã®å€ã¯ããŒãã«ã«ã°ã«ãŒãåã§ããŸãã ããŒãã«ã®åè¡ã«ã¯ãç¹å®ã®ãªãœãŒã¹ã«é¢é£ä»ããããå€æ°ã®å€ãã°ã«ãŒãåãããŠããŸãã åå€ã«ã¢ã¯ã»ã¹ããã«ã¯ãããŒãã«ã®åã«å²ãåœãŠãããOIDã«ããªãœãŒã¹ã®èª¬æè¡ãå®çŸ©ããèå¥åãè¿œå ããå¿ èŠããããŸãã ãã®è¡èå¥åããªãœãŒã¹ã€ã³ããã¯ã¹ãšåŒã³ãŸãã
ã€ã³ã¿ãŒãã§ãŒã¹ã®ãªã¹ãïŒ1.3.6.1.2.1.2ïŒãããŒãªã³ã°ããå ŽåãæŽæ°ã¯ãªãœãŒã¹èå¥åãšããŠæ©èœããŸãããä»ã®ããŒãã«ã®å Žåã¯ãIPã¢ãã¬ã¹ãŸãã¯ä»æ§ã§å®çŸ©ãããäœãã«ããããšãã§ããŸãã å°é£ãªã®ã¯ãäºåã«ããŒãªã³ã°ããããªãœãŒã¹ã®ã€ã³ããã¯ã¹ããããããGETãªã¯ãšã¹ãã䜿çšããŠé¢å¿ã®ããå€æ°ã®å€ãååŸã§ããªããšããäºå®ã«ãããŸãã
ããŒãã«ã®å€ãèªã¿åãã«ã¯ãã¯ãšãªã§æå®ãããOIDã®èŸæžåŒé åºã«åŸã£ãŠOIDãšå€æ°ã®å€ãè¿ãGETNEXTã¯ãšãªã䜿çšããå¿ èŠããããŸãã ãããã£ãŠãé¢å¿ã®ããå€æ°ã®OIDã®ãã¬ãã£ãã¯ã¹ã§ããOIDåãæž¡ããšãããŒãã«ã®æåã®è¡ãã察å¿ããå€ãååŸããŸãã 次ã®è¡ã®å€ãååŸããããã«ãå¿çã®äžéšãšããŠåä¿¡ããOIDãæåã®ã¯ãšãªã«æž¡ããªã©ãããŒãã«ãå®å šã«ã¹ãã£ã³ããããŸã§æž¡ããŸãã
ïŒéä¿¡ããããªã¯ãšã¹ãã®æ°ãæžããããšã«ããïŒããã©ãŒãã³ã¹ãæé©åããããã«ã1ã€ã®ãªã¯ãšã¹ãã§è€æ°ã®åã®OIDã転éã§ããŸãã ããã«ãSNMPã®ããŒãžã§ã³2ã§ã¯ãBULKèŠæ±ãçæããæ©èœãè¿œå ãããŸããã 1ã€ã®BULKèŠæ±ã¯ã次ã ã«å®è¡ãããè€æ°ã®GETNEXTèŠæ±ã眮ãæããŸããããã«ããã1ã€ã®èŠæ±ã§ããŒãã«å šäœãèªã¿åãããšãã§ããŸãïŒååãªBULKå€ã䜿çšïŒã ç§ã¯ãã§ã«ãã®ãã¹ãŠã«ã€ããŠè©±ããŸããã
ããããã¹ãŠæ確ã«ããããã«ç¹°ãè¿ããŸã-ããŒãã«ã¯äžå®ã§ã¯ãããŸããïŒ ã€ã³ã¿ãŒãã§ã€ã¹ããŒãã«ã®èª¬æïŒããšãã°ãããŒã¿ããŒã¹å ã®ã©ããã«ïŒãšOIDã®å²ãåœãŠãæåã§è¡ãããšã¯ããŸã£ããæå³ããããŸããã ããŒãã«ã®è¡ã¯ãæ©åšã®åæ§æäžã«è¿œå ããã³åé€ã§ããŸãã ããã«ãæ¢åã®ã€ã³ã¿ãŒãã§ã€ã¹ã®ã€ã³ããã¯ã¹ãå€æŽãããå ŽåããããŸãïŒ å®éãSNMPç£èŠã·ã¹ãã ã®ã¿ã¹ã¯ã®1ã€ã¯ã衚瀺ãããããŒãã«ã«å¯Ÿãããã¹ãŠã®å€æŽã®è¿œè·¡ãèªååããããšã§ãã
ããŒã¿ããŒã¹ã§ã¯ã©ã®ããã«è¡šç€ºãããŸããïŒ ãšãŠãç°¡åã§ãïŒ
ç£èŠããã»ã¹äžã«ååŸããããŒã¿ã¯ããªãœãŒã¹ïŒae_resourceïŒã«ãã€ã³ãããŸãã ãªãœãŒã¹ã¯ãé çªã«2ã¬ãã«ã®éå±€ã«ãªã³ã¯ãããŸãã æäžäœã§ã¯ãããã€ã¹ãªãœãŒã¹ã衚瀺ãããŸãã owner_idã«ãããšãããšãã°ã€ã³ã¿ãŒãã§ãŒã¹ãªã©ã®åãªãœãŒã¹ã¯ããã«é¢é£ä»ããããŸãïŒãããã¯ã€ã³ã¿ãŒãã§ãŒã¹ã§ãããä»ã®ãã®ã§ã¯ãªããšããäºå®ã¯ãae_resource_typeãã£ã¬ã¯ããªãŒã®type_idå€ã«ãã£ãŠæ±ºå®ãããŸãïŒã 芪ããã³ãã¹ãŠã®åãªãœãŒã¹ã®device_idå€ã¯äžèŽããããŒããŠã§ã¢ã®èª¬æãæããŸãã
ae_resourceããŒãã«ã«start_dateãã£ãŒã«ããšend_dateãã£ãŒã«ããããããšãããããŸãã ããããææ°ã®ç¶æ ã«ä¿ã€ããšãç§ãã¡ã®ä»äºã§ãã å¿ èŠã«å¿ããŠæ°ãããªãœãŒã¹ãäœæããstart_dateã«ã¢ã¯ã·ã§ã³ã®éå§æ¥ãèšå®ããend_dateãèšå®ããŠå»æ¢ããããªãœãŒã¹ã®ã¢ã¯ã·ã§ã³ãçµäºããå¿ èŠããããŸãã ãªãœãŒã¹ãèå¥ããããã«ãååãã£ãŒã«ãã䜿çšãããŸãïŒã€ã³ã¿ãŒãã§ãŒã¹ã®å ŽåãifDescrå±æ§ã®å€ã¯1.3.6.1.2.1.2.2.1.2ã§ãïŒã res_numãã£ãŒã«ãã«ãªãœãŒã¹ã€ã³ããã¯ã¹ãä¿åããŸãïŒå€æŽããå Žåã¯ãå€ãã€ã³ããã¯ã¹å€ãæã€ãªãœãŒã¹ãéããŠãããæ°ãããªãœãŒã¹ãäœæããå¿ èŠããããŸãïŒã
ã€ã³ã¿ãŒãã§ã€ã¹ã®ãªã¹ããææ°ã®ç¶æ ã«ä¿ã€å¿ èŠãããããšããããŒã¿ãåŠçããå¿ èŠãããäž»ãªçç±ã§ãïŒãã ããéåžžãåä¿¡ããããŒã¿ãããŒãã«ã«æ¿å ¥ããã®ã«ãããæéã¯ã¯ããã«çããªããŸãïŒã ãããããšã«ããããŒã¿ãåŠçããå Žåããããæ倧éã«æŽ»çšããŠã¿ãŸãããïŒ ç£èŠã®ããã»ã¹ã§ã¯ãå€ãã®ããŒã¿ãååŸãããŸããããã®äžéšã¯å€åããªããããããã«å€åããŸãã éèŠãªå€æŽã®ã¿ãä¿åããå ŽåãããŒã¿ããŒã¹ã«ä¿åãããããŒã¿ã®éãæžããããšãã§ããŸãïŒããã¯ãããªã¥ãŒã ãšããã©ãŒãã³ã¹ã®äž¡æ¹ã«æçãªå¹æããããããŸãïŒã ããããã©ã®å€æŽãéèŠã§ããããå€æããæ¹æ³ã¯ïŒ æ¿æ²»å®¶ã¯ããã§ç§ãã¡ãå©ããŸãïŒ
åãåãåãã©ã¡ãŒã¿ãŒã®å€ã¯ãç¹å®ã®ãã¡ã€ã³ïŒae_domainïŒã«é¢é£ä»ããããŸãã æ£èŠè¡šçŸïŒregexpïŒã¯ãå€ã®æ€èšŒã«åœ¹ç«ã¡ãŸãã ããŒã¿ããŒã¹ã«ä¿åããåã«ãå€ãä»ã®ãã¡ã€ã³ã«å€æã§ããŸãïŒããšãã°ãæååã16é²è¡šèšã§ååŸããŸããããã¯ããã䜿ãæ £ãã圢åŒã«å€æãããšäŸ¿å©ã§ãïŒã å€æèŠåã¯ãae_domain_convertããŒãã«ã«ãã£ãŠæ±ºå®ãããŸãã
ã©ã®ãããªå€æŽãéèŠãšã¿ãªãããŸããïŒ ãã¡ã€ã³ã«äŸåããŸãã ããã©ã«ãã§ã¯ãå€ã®å€æŽã¯éèŠãšã¿ãªãããŸãïŒã€ãŸããå€ãå€æŽãããŠããªãå ŽåãããŒã¿ããŒã¹ãžã®æžã蟌ã¿ã¯å®è¡ãããŸããïŒã äžéšã®ãã©ã¡ãŒã¿ãŒã§ã¯ãç¹å¥ãªã«ãŒã«ãèšå®ããããšãçã«ããªã£ãŠããŸãã ããšãã°ãsysUpTimeïŒå¯Ÿå¿ããå€æåŸïŒã¯ãå調ã«å¢å ããæ°å€ã§ãã ãã®å€ãå°ãããããšããã¹ããåèµ·åããããšãæå³ããŸãã ãã®ãã¡ã€ã³ã«ç¹å¥ãªããªã·ãŒãèšå®ãããšãå€ãæžå°ããã€ãã³ãïŒåèµ·åãæå³ããïŒã®ã¿ãããŒã¿ããŒã¹ã«æžã蟌ãããšãã§ããŸããã以åã®å€ïŒã€ãŸããæ倧éæã¢ããã¿ã€ã ïŒã¯åä¿¡ãããã®ã§ã¯ãªãããŒã¿ããŒã¹ã«æžã蟌ãŸããŸãã
ae_thresholdã§ã¯ããããå€ãèšå®ããŸãããã®äº€å·®ã¯ïŒç¹å®ã®æ¹åã§ïŒéèŠãªå€åãšèŠãªãããŸãã ããã«ãåã®å€ãšåä¿¡ããå€ã®å·®ã®çµ¶å¯Ÿå€ã決å®ããç¹å¥ãªã¿ã€ãã®ãããå€ïŒãã«ã¿ïŒãå°å ¥ããŸãã ãã®ãããªãããå€ã®èšå®ã¯ãããšãã°ifInOctetsïŒ1.3.6.1.2.1.2.2.1.10ïŒãªã©ã®ãã©ãã£ãã¯ã«ãŠã³ã¿ãŒã«äŸ¿å©ã§ãã
å®å šã«ãããŒã¿ã¹ããŒãã¯æ¬¡ã®ããã«ãªããŸãã
ããŒã¿ã¹ããŒã
ã¹ã¯ãªãã
create sequence ae_platform_model_seq start with 100; create table ae_platform_model ( id number not null, name varchar2(30) not null, description varchar2(300) ); comment on table ae_platform_model is ' '; create unique index ae_platform_model_pk on ae_platform_model(id); alter table ae_platform_model add constraint pk_ae_platform_model primary key(id); create sequence ae_device_seq cache 100; create table ae_device ( id number not null, model_id number not null, start_date date default sysdate not null, end_date date default null ); comment on table ae_device is ''; create unique index ae_device_pk on ae_device(id); create index ae_device_fk on ae_device(device_id); create index ae_device_model_fk on ae_device(model_id); create index ae_device_zone_fk on ae_device(zone_id); alter table ae_device add constraint pk_ae_device primary key(id); alter table ae_device add constraint fk_ae_device_model foreign key (model_id) references ae_platform_model(id); create sequence ae_resource_class_seq start with 100; create table ae_resource_class ( id number not null, owner_id number, is_logical number(1) not null, name varchar2(30) not null, description varchar2(300) ); comment on table ae_resource_class is ' '; comment on column ae_resource_class.is_logical is ' '; create unique index ae_resource_class_pk on ae_resource_class(id); create index ae_resource_class_fk on ae_resource_class(owner_id); alter table ae_resource_class add constraint ae_resource_class_ck check (is_logical in (0, 1)); alter table ae_resource_class add constraint pk_ae_resource_class primary key(id); create sequence ae_resource_type_seq start with 100; create table ae_resource_type ( id number not null, owner_id number, parent_id number, class_id number not null, name varchar2(30) not null, description varchar2(300) ); comment on table ae_resource_type is ' '; create unique index ae_resource_type_pk on ae_resource_type(id); create index ae_resource_type_owner_fk on ae_resource_type(owner_id); create index ae_resource_type_parent_fk on ae_resource_type(parent_id); alter table ae_resource_type add constraint pk_ae_resource_type primary key(id); alter table ae_resource_type add constraint fk_ae_resource_type foreign key (class_id) references ae_resource_class(id); alter table ae_resource_type add constraint fk_ae_resource_type_owner foreign key (owner_id) references ae_resource_type(id); alter table ae_resource_type add constraint fk_ae_resource_type_parent foreign key (parent_id) references ae_resource_type(id); create sequence ae_resource_seq cache 100; create table ae_resource ( id number not null, device_id number not null, owner_id number default null, type_id number not null, name varchar2(1000) not null, res_num varchar2(300) not null, res_id number, tmp_id number, start_date date default sysdate not null, end_date date default null ); create unique index ae_resource_pk on ae_resource(id); create index ae_res_dev_fk on ae_resource(device_id); create index ae_res_dev_type_fk on ae_resource(type_id); create index ae_res_dev_res_fk on ae_resource(res_id); create index ae_res_dev_res_tmp_fk on ae_resource(tmp_id); alter table ae_resource add constraint pk_ae_resource primary key(id); alter table ae_resource add constraint fk_ae_res_device foreign key (device_id) references ae_device(id); alter table ae_resource add constraint fk_ae_res_dev_parent foreign key (owner_id) references ae_resource(id); alter table ae_resource add constraint fk_ae_res_dev_type foreign key (type_id) references ae_resource_type(id); create table ae_policy_type ( id number not null, name varchar2(30) not null, description varchar2(100) ); comment on table ae_policy_type is ' '; create unique index ae_policy_type_pk on ae_policy_type(id); create unique index ae_policy_type_uk on ae_policy_type(name); alter table ae_policy_type add constraint pk_ae_policy_type primary key(id); create table ae_state_policy ( id number not null, type_id number not null, name varchar2(30) not null, description varchar2(100) ); comment on table ae_state_policy is ' '; create unique index ae_state_policy_pk on ae_state_policy(id); create index ae_state_policy_fk on ae_state_policy(type_id); alter table ae_state_policy add constraint pk_ae_state_policy primary key(id); alter table ae_state_policy add constraint fk_ae_state_policy foreign key (type_id) references ae_policy_type(id); create table ae_threshold_type ( id number not null, name varchar2(30) not null, description varchar2(300) ); create unique index ae_threshold_type_pk on ae_threshold_type(id); alter table ae_threshold_type add constraint pk_ae_threshold_type primary key(id); create sequence ae_threshold_seq start with 100; create table ae_threshold ( id number not null, type_id number not null, policy_id number not null, value varchar2(100) not null ); create unique index ae_threshold_pk on ae_threshold(id); create index ae_threshold_direction_fk on ae_threshold(type_id); create index ae_threshold_profile_fk on ae_threshold(policy_id); alter table ae_threshold add constraint pk_ae_threshold primary key(id); alter table ae_threshold add constraint fk_ae_threshold_type foreign key (type_id) references ae_threshold_type(id); alter table ae_threshold add constraint fk_ae_threshold_policy foreign key (policy_id) references ae_state_policy(id); create sequence ae_domain_convert_seq start with 100; create table ae_domain ( id number not null, policy_id number default null, regexp varchar2(100), is_case_sens number(1) default 0 not null, description varchar2(100) ); create unique index ae_domain_pk on ae_domain(id); create index ae_domain_fk on ae_domain(policy_id); alter table ae_domain add constraint ae_domain_ck check (is_case_sens in (0, 1)); alter table ae_domain add constraint pk_ae_domain primary key(id); alter table ae_domain add constraint fk_ae_domain foreign key (policy_id) references ae_state_policy(id); create sequence ae_parameter_seq start with 1000; create table ae_parameter ( id number not null, domain_id number not null, parent_id number, name varchar2(30) not null, description varchar2(100) ); create unique index ae_parameter_pk on ae_parameter(id); create unique index ae_parameter_uk on ae_parameter(name); create index ae_parameter_domain_fk on ae_parameter(domain_id); create index ae_parameter_parent_fk on ae_parameter(parent_id); alter table ae_parameter add constraint pk_ae_parameter primary key(id); alter table ae_parameter add constraint fk_ae_parameter_domain foreign key (domain_id) references ae_domain(id); alter table ae_parameter add constraint fk_ae_parameter foreign key (parent_id) references ae_parameter(id); create sequence ae_state_seq cache 100; create table ae_state ( id number not null, res_id number not null, param_id number not null, value varchar2(300), datetime timestamp default current_timestamp not null ); comment on table ae_state is ' '; comment on column ae_state.datetime is ' '; create unique index ae_state_pk on ae_state(id); create index ae_state_res_fk on ae_state(res_id); create index ae_state_param_fk on ae_state(param_id); alter table ae_state add constraint pk_ae_state primary key(id); alter table ae_state add constraint fk_ae_state_res foreign key (res_id) references ae_resource(id); alter table ae_state add constraint fk_ae_state_param foreign key (param_id) references ae_parameter(id); create sequence ae_state_log_seq cache 100; create table ae_state_log ( id number not null, res_id number not null, param_id number not null, value varchar2(300), datetime timestamp default current_timestamp not null ) pctfree 0 partition by range (datetime) ( partition ae_state_log_p1 values less than (maxvalue) ); comment on table ae_state_log is ' '; create unique index ae_state_log_pk on ae_state_log(datetime, id) local; alter table ae_state_log add constraint pk_ae_state_log primary key(datetime, id); create sequence ae_profile_type_seq; create table ae_profile_type ( id number not null, name varchar2(30) not null, description varchar2(100) ); create unique index ae_profile_type_pk on ae_profile_type(id); create unique index ae_profile_type_uk on ae_profile_type(name); alter table ae_profile_type add constraint pk_ae_profile_type primary key(id); create sequence ae_profile_seq; create table ae_profile ( id number not null, type_id number not null, is_default number(1) default 0 not null, model_id number not null, script_id number default null, name varchar2(30) not null, description varchar2(100) ); create unique index ae_profile_pk on ae_profile(id); create index ae_profile_type_fk on ae_profile(type_id); create index ae_profile_model_fk on ae_profile(model_id); create index ae_profile_script_fk on ae_profile(script_id); alter table ae_profile add constraint ae_profile_ck check (is_default in (0, 1)); alter table ae_profile add constraint pk_ae_profile primary key(id); alter table ae_profile add constraint fk_ae_profile_type foreign key (type_id) references ae_profile_type(id); create sequence ae_profile_detail_seq; create table ae_profile_detail ( id number not null, type_id number not null, profile_id number not null, model_id number not null, param_id number not null ); create unique index ae_profile_detail_pk on ae_profile_detail(id); create index ae_profile_detail_fk on ae_profile_detail(profile_id); create index ae_profile_detail_type_fk on ae_profile_detail(type_id); create index ae_profile_detail_model_fk on ae_profile_detail(model_id); create index ae_profile_detail_param_fk on ae_profile_detail(param_id); alter table ae_profile_detail add constraint pk_ae_profile_detail primary key(id); alter table ae_profile_detail add constraint fk_ae_profile_detail foreign key (profile_id) references ae_profile(id); alter table ae_profile_detail add constraint fk_ae_profile_detail_type foreign key (type_id) references ae_resource_type(id); alter table ae_profile_detail add constraint fk_ae_profile_detail_model foreign key (model_id) references ae_platform_model(id); create global temporary table ae_state_tmp ( id number not null, device_id number not null, profile_id number not null, param_id number not null, num varchar2(300), value varchar2(300), datetime timestamp default current_timestamp not null ) on commit delete rows; create index ae_state_tmp_ix on ae_state_tmp(device_id, profile_id, param_id, num);
ããã§ããã£ã¬ã¯ããªãããŒã¿ã§åããããšãã§ããŸãã
è©ŠéšããŒã¿
Insert into AE_POLICY_TYPE (ID, NAME, DESCRIPTION) Values (1, 'default', NULL); Insert into AE_POLICY_TYPE (ID, NAME, DESCRIPTION) Values (2, 'uptime', NULL); Insert into AE_POLICY_TYPE (ID, NAME, DESCRIPTION) Values (3, 'threshold', NULL); COMMIT; Insert into AE_STATE_POLICY (ID, NAME, DESCRIPTION, TYPE_ID) Values (1, 'default', NULL, 1); Insert into AE_STATE_POLICY (ID, NAME, DESCRIPTION, TYPE_ID) Values (2, 'uptime', NULL, 2); COMMIT; Insert into AE_DOMAIN (ID, REGEXP, IS_CASE_SENS, DESCRIPTION, POLICY_ID) Values (10, '((\d+)\D*,\s*)?(\d+):(\d+):(\d+)(\.\d+)?', 0, 'SNMP uptime', 1); Insert into AE_DOMAIN (ID, REGEXP, IS_CASE_SENS, DESCRIPTION, POLICY_ID) Values (11, '\d+', 0, 'SNMP ', 1); Insert into AE_DOMAIN (ID, REGEXP, IS_CASE_SENS, DESCRIPTION, POLICY_ID) Values (12, '([a-fA-F\d])+', 0, 'SNMP ', 1); Insert into AE_DOMAIN (ID, REGEXP, IS_CASE_SENS, DESCRIPTION, POLICY_ID) Values (13, '.*', 0, 'SNMP ', 1); Insert into AE_DOMAIN (ID, REGEXP, IS_CASE_SENS, DESCRIPTION, POLICY_ID) Values (14, '\d+', 0, 'SNMP uptime ( )', 2); COMMIT; Insert into AE_PARAMETER (ID, DOMAIN_ID, PARENT_ID, NAME, DESCRIPTION) Values (101, 14, NULL, 'uptime', 'SNMP Uptime'); Insert into AE_PARAMETER (ID, DOMAIN_ID, PARENT_ID, NAME, DESCRIPTION) Values (102, 11, NULL, 'ifIndex', ' '); Insert into AE_PARAMETER (ID, DOMAIN_ID, PARENT_ID, NAME, DESCRIPTION) Values (103, 13, NULL, 'ifName', ' '); Insert into AE_PARAMETER (ID, DOMAIN_ID, PARENT_ID, NAME, DESCRIPTION) Values (104, 11, NULL, 'ifInOctets', ' '); Insert into AE_PARAMETER (ID, DOMAIN_ID, PARENT_ID, NAME, DESCRIPTION) Values (105, 11, NULL, 'ifOutOctets', ' '); COMMIT; Insert into AE_PLATFORM_MODEL (ID, NAME, DESCRIPTION) Values (1, 'test', NULL); COMMIT; Insert into AE_PROFILE_TYPE (ID, NAME, DESCRIPTION) Values (1, 'mon', ''); COMMIT; Insert into AE_PROFILE (ID, TYPE_ID, IS_DEFAULT, MODEL_ID, SCRIPT_ID, NAME, DESCRIPTION) Values (1, 1, 1, 1, NULL, 'test', NULL); COMMIT; Insert into AE_RESOURCE_CLASS (ID, IS_LOGICAL, NAME, DESCRIPTION, OWNER_ID) Values (1, 0, '', NULL, NULL); Insert into AE_RESOURCE_CLASS (ID, IS_LOGICAL, NAME, DESCRIPTION, OWNER_ID) Values (2, 0, '', NULL, 1); COMMIT; Insert into AE_RESOURCE_TYPE (ID, CLASS_ID, NAME, DESCRIPTION, OWNER_ID, PARENT_ID) Values (1, 1, 'Host', NULL, NULL, NULL); Insert into AE_RESOURCE_TYPE (ID, CLASS_ID, NAME, DESCRIPTION, OWNER_ID, PARENT_ID) Values (2, 2, 'Interface', NULL, 1, NULL); COMMIT; Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (4, 2, 1, 1, 104); Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (5, 2, 1, 1, 105); Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (6, 1, 1, 1, 1); Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (1, 1, 1, 1, 101); Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (2, 2, 1, 1, 102); Insert into AE_PROFILE_DETAIL (ID, TYPE_ID, PROFILE_ID, MODEL_ID, PARAM_ID) Values (3, 2, 1, 1, 103); COMMIT; Insert into AE_DEVICE (ID, MODEL_ID, START_DATE, END_DATE) Values (0, 1, TO_DATE('10/30/2013 15:37:16', 'MM/DD/YYYY HH24:MI:SS'), NULL); COMMIT; Insert into AE_RESOURCE (ID, DEVICE_ID, OWNER_ID, TYPE_ID, NAME, RES_NUM, RES_ID, START_DATE, END_DATE, TMP_ID) Values (1, 0, NULL, 1, '127.0.0.1', '0', NULL, TO_DATE('10/30/2013 15:24:44', 'MM/DD/YYYY HH24:MI:SS'), NULL, NULL); COMMIT; Insert into AE_THRESHOLD_TYPE (ID, NAME, DESCRIPTION) Values (1, 'increase', ''); Insert into AE_THRESHOLD_TYPE (ID, NAME, DESCRIPTION) Values (2, 'decrease', ''); Insert into AE_THRESHOLD_TYPE (ID, NAME, DESCRIPTION) Values (3, 'delta', ''); COMMIT; Insert into AE_THRESHOLD (ID, TYPE_ID, POLICY_ID, VALUE) Values (1, 3, 1, '100'); COMMIT;
ãããŠããã¹ãã³ãŒãã®ãã©ãããæºåããŸãã
ãã¹ãã³ãŒã
package com.acme.ae.tests.jdbc; import oracle.jdbc.driver.OracleCallableStatement; import oracle.sql.*; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; public class Test { private final static String CLASS_NAME = "oracle.jdbc.driver.OracleDriver"; private final static String USER_CONN = "jdbc:oracle:thin:@192.168.124.5:1523:new11"; private final static String USER_NAME = "ais"; private final static String USER_PASS = "ais"; private final static boolean AUTO_COMMIT_MODE = false; private final static int BULK_SIZE = 100; private final static int ALL_SIZE = 1000; private final static String TRACE_ON_SQL = "ALTER SESSION SET EVENTS '10046 trace name context forever, level 12'"; private final static Long DEVICE_ID = 0L; private final static Long PROFILE_ID = 1L; private final static Long UPTIME_PARAM_ID = 101L; private final static Long IFNAME_PARAM_ID = 103L; private final static Long INOCT_PARAM_ID = 104L; private final static String FAKE_NUM_VALUE = "0"; private Connection c = null; private void start() throws ClassNotFoundException, SQLException { Class.forName(CLASS_NAME); c = DriverManager.getConnection(USER_CONN, USER_NAME, USER_PASS); c.setAutoCommit(AUTO_COMMIT_MODE); CallableStatement st = c.prepareCall(TRACE_ON_SQL); try { st.execute(); } finally { st.close(); } } private void stop() throws SQLException { if (c != null) { c.close(); } } public static void main(String[] args) { Test t = new Test(); try { try { t.start(); t.test_plsql(); // } finally { t.stop(); } } catch (Exception e) { System.out.println(e.toString()); } } }
ããã©ãŒãã³ã¹ã®è©³çŽ°ãªåæã®ããã«ããµãŒããŒäžã®ã€ãã³ã10046ãã¬ãŒã¹ã䜿çšãã tkprofãŠãŒãã£ãªãã£ã«ãããã¬ãŒã¹ã®åŸç¶ã®åŠçãè¡ããŸãã
æãé ãæ¹æ³ïŒplsqlïŒ
æãæçœãªåäžã¬ã³ãŒãåŠçã§ãã¹ããéå§ããŸãã å®éã«ããã©ãŒãã³ã¹ãè©äŸ¡ããããšã«å ããŠããã®ã³ãŒããæžãããšã§ãããŒã¿ã®åŠçæ¹æ³ãããããç解ããããšãã§ããŸãã
PL / SQLã³ãŒã
CREATE OR REPLACE package AIS.ae_monitoring as procedure addValue( p_device in number , p_profile in number , p_param in number , p_num in varchar2 , p_val in varchar2 ); end ae_monitoring; / CREATE OR REPLACE package body AIS.ae_monitoring as g_ifName_parameter constant number default 103; g_default_policy constant number default 1; g_uptime_policy constant number default 2; g_threshold_policy constant number default 3; g_increase_type constant number default 1; g_decrease_type constant number default 2; g_delta_type constant number default 3; procedure addValue( p_device in number , p_profile in number , p_param in number , p_num in varchar2 , p_val in varchar2 ) as cursor c_res(p_type number) is select r.id, r.name from ae_resource r where r.device_id = p_device and r.res_num = p_num and r.type_id = p_type and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1); cursor c_state(p_resid number) is select s.value from ae_state s where s.res_id = p_resid and s.param_id = p_param; l_resid ae_resource.id%type default null; l_resname ae_resource.name%type default null; l_oldval ae_state.value%type default null; l_restype ae_profile_detail.type_id%type default null; l_owntype ae_resource_type.owner_id%type default null; l_owner ae_resource.id%type default null; l_policy ae_state_policy.type_id%type default null; l_polid ae_state_policy.id%type default null; l_count number default 0; begin -- select d.type_id, r.owner_id into l_restype, l_owntype from ae_profile_detail d inner join ae_resource_type r on (r.id = d.type_id) where d.profile_id = p_profile and d.param_id = p_param; -- ID if not l_owntype is null then select r.id into l_owner from ae_resource r where r.device_id = p_device and r.type_id = l_owntype; end if; -- if p_param = g_ifName_parameter then open c_res(l_restype); fetch c_res into l_resid, l_resname; if c_res%notfound or l_resname <> p_val then -- update ae_resource set end_date = sysdate where id = l_resid; -- insert into ae_resource(id, device_id, owner_id, type_id, res_num, name) values (ae_resource_seq.nextval, p_device, l_owner, l_restype, p_num, p_val); end if; close c_res; return; end if; -- ID open c_res(l_restype); fetch c_res into l_resid, l_resname; if c_res%notfound then -- , insert into ae_resource(id, device_id, owner_id, type_id, res_num, name) values (ae_resource_seq.nextval, p_device, l_owner, l_restype, p_num, p_val) returning id into l_resid; end if; -- open c_state(l_resid); fetch c_state into l_oldval; if c_state%notfound then l_oldval := null; end if; close c_state; -- select l.type_id, l.id into l_policy, l_polid from ae_parameter p inner join ae_domain d on (d.id = p.domain_id) inner join ae_state_policy l on (l.id = d.policy_id) where p.id = p_param; -- select count(*) into l_count from ae_threshold t where t.policy_id = l_polid and (( t.type_id = g_increase_type and l_oldval <= t.value and p_val >= t.value ) or ( t.type_id = g_decrease_type and l_oldval >= t.value and p_val <= t.value ) or ( t.type_id = g_delta_type and abs(p_val - l_oldval) >= t.value )); -- ae_state_log if l_oldval is null or l_count > 0 or ( l_policy = g_uptime_policy and p_val < l_oldval) or ( l_policy = g_default_policy and p_val <> l_oldval) then insert into ae_state_log(id, res_id, param_id, value) values (ae_state_log_seq.nextval, l_resid, p_param, decode(l_policy, g_uptime_policy, nvl(l_oldval, p_val), p_val)); end if; -- ae_state update ae_state set value = p_val , datetime = current_timestamp where res_id = l_resid and param_id = p_param; if sql%rowcount = 0 then insert into ae_state(id, param_id, res_id, value) values (ae_state_seq.nextval, p_param, l_resid, p_val); end if; close c_res; exception when others then if c_res%isopen then close c_res; end if; if c_state%isopen then close c_state; end if; raise; end; end ae_monitoring; /
Javaã³ãŒã
private final static String ADD_VAL_SQL = "begin ae_monitoring.addValue(?,?,?,?,?); end;"; private void test_plsql() throws SQLException { System.out.println("test_plsql:"); CallableStatement st = c.prepareCall(ADD_VAL_SQL); Long timestamp = System.currentTimeMillis(); Long uptime = 0L; Long inoct = 0L; try { for (int i = 1; i <= ALL_SIZE; i++) { // uptime st.setLong(1, DEVICE_ID); st.setLong(2, PROFILE_ID); st.setLong(3, UPTIME_PARAM_ID); st.setString(4, FAKE_NUM_VALUE); st.setString(5, uptime.toString()); st.execute(); // st.setLong(1, DEVICE_ID); st.setLong(2, PROFILE_ID); st.setLong(3, IFNAME_PARAM_ID); st.setString(4, Integer.toString((i % 100) + 1)); st.setString(5, Integer.toString((i % 100) + 1)); st.execute(); // st.setLong(1, DEVICE_ID); st.setLong(2, PROFILE_ID); st.setLong(3, INOCT_PARAM_ID); st.setString(4, Integer.toString((i % 100) + 1)); st.setString(5, inoct.toString()); st.execute(); // uptime += 100L; if (uptime >= 1000) { uptime = 0L; } inoct += 10L; } } finally { st.close(); } Long delta_1 = System.currentTimeMillis() - timestamp; System.out.println((ALL_SIZE * 1000L) / delta_1); timestamp = System.currentTimeMillis(); c.commit(); Long delta_2 = System.currentTimeMillis() - timestamp; System.out.println(delta_2); System.out.println((ALL_SIZE * 1000L) / (delta_1 - delta_2)); }
æããã«ããã®ã³ãŒããã€ã³ã¿ãŒãã§ã€ã¹ã®ãªã¹ããæ£ãããµããŒãããã«ã¯ããªãœãŒã¹ã®ä»ã®å±æ§ã®åã«ã€ã³ã¿ãŒãã§ã€ã¹ã®ååãããŒã¿ããŒã¹ã«è»¢éããå¿ èŠããããŸãã
ãã¹ãçµæã¯éåžžã«äºæž¬å¯èœã§ãïŒ
çµæ
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 1 0.00 0.00 0 0 0 0 Execute 3000 4.23 4.13 7 102942 6615 3000 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 3001 4.23 4.13 7 102942 6615 3000 Misses in library cache during parse: 1 Misses in library cache during execute: 1 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 3002 0.00 0.00 SQL*Net message from client 3002 5.92 7.12 latch: library cache 4 0.00 0.00 log file sync 1 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 69 0.00 0.00 0 0 0 0 Execute 17261 2.42 2.36 7 9042 6615 3160 Fetch 14000 0.38 0.37 0 93900 0 13899 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 31330 2.81 2.74 7 102942 6615 17059 Misses in library cache during parse: 10 Misses in library cache during execute: 10 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ db file sequential read 7 0.00 0.00
éåžžã«å€ãã®ãªã¯ãšã¹ããå®è¡ãããããã¯ãŒã¯éä¿¡ã«å€ãã®æéãè²»ãããŠããŸãã
倧éåŠçã䜿çšããŸãïŒäžæïŒ
ãªãŒããŒãããã«å¯ŸåŠããæãæ ¹æ¬çãªæ¹æ³ã¯ã倧éåŠçã«ç§»è¡ããããšã§ãã ãŸããåŠçã®ããã«ããŒã¿ã»ãããäœããã®ããŒãã«ã«ä¿åãã次ã«1ã€ã®ã¬ã³ãŒãã§ã¯ãªãäžåºŠã«ãã¹ãŠã®ããŒã¿ãåŠçã§ããŸãã ãã¡ãããäžéããŒã¿ã¹ãã¬ãŒãžã«ã¯éåžžã®ããŒãã«ã䜿çšã§ããŸããããã®ã³ã°ã®ãªãŒããŒããããåæžãããããããããã®ç®çã§GTTã䜿çšããæ¹ãããæçã§ãã
ããŒã¿ãäžæããŒãã«ã«æ¿å ¥ããã«ã¯ãã¹ãã¢ãããã·ãŒãžã£ã®åŒã³åºãã§ã¯ãªãDMLã䜿çšããŸããããã«ããã JDBCãããã䜿çšããŠãããã¯ãŒã¯ãªãŒããŒããããåæžã§ããŸãã
ãã®ã¢ãããŒãã䜿çšããå Žåãä»ã®ãã©ã¡ãŒã¿ãŒã®åã«ã€ã³ã¿ãŒãã§ã€ã¹åãåŠçããå¿ èŠã¯ãããŸããã åŠçããããã¹ãŠã®ã€ã³ã¿ãŒãã§ãŒã¹ã®ååããåŠçãããããŒã¿ã»ããã«ããã°ååã§ãã
PL / SQLã³ãŒã
CREATE OR REPLACE package AIS.ae_monitoring as procedure saveValues; end ae_monitoring; / CREATE OR REPLACE package body AIS.ae_monitoring as g_ifName_parameter constant number default 103; g_default_policy constant number default 1; g_uptime_policy constant number default 2; g_threshold_policy constant number default 3; g_increase_type constant number default 1; g_decrease_type constant number default 2; g_delta_type constant number default 3; procedure saveValues as begin -- , merge into ae_resource d using ( select t.id, t.device_id, t.num, t.value name, p.type_id, o.id owner_id from ae_state_tmp t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource_type r on (r.id = p.type_id) left join ae_resource o on (o.device_id = t.device_id and o.type_id = r.owner_id) where t.param_id = g_ifName_parameter ) s on ( d.device_id = s.device_id and d.res_num = s.num and d.type_id = s.type_id and d.start_date <= sysdate and sysdate <= nvl(d.end_date, sysdate + 1) ) when matched then update set d.tmp_id = s.id where d.name <> s.name when not matched then insert (id, device_id, owner_id, type_id, res_num, name) values (ae_resource_seq.nextval, s.device_id, s.owner_id, s.type_id, s.num, s.name); -- ae_resource insert into ae_resource(id, device_id, owner_id, type_id, res_num, name) select ae_resource_seq.nextval, t.device_id, o.id, p.type_id, t.num, t.value from ae_state_tmp t inner join ae_resource c on (c.tmp_id = t.id) inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource_type r on (r.id = p.type_id) left join ae_resource o on (o.device_id = t.device_id and o.type_id = r.owner_id); -- update ae_resource set end_date = sysdate , tmp_id = null where tmp_id > 0; -- ae_state_log insert into ae_state_log(id, res_id, param_id, value) select ae_state_log_seq.nextval, id, param_id, value from ( select distinct r.id, t.param_id, decode(l.type_id, g_uptime_policy, nvl(s.value, t.value), t.value) value from ae_state_tmp t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) left join ae_state s on (s.res_id = r.id and s.param_id = t.param_id) inner join ae_parameter a on (a.id = p.param_id) inner join ae_domain d on (d.id = a.domain_id) inner join ae_state_policy l on (l.id = d.policy_id) left join ae_threshold h on ( h.policy_id = l.id and (( h.type_id = g_increase_type and s.value <= h.value and t.value >= h.value ) or ( h.type_id = g_decrease_type and s.value >= h.value and t.value <= h.value ) or ( h.type_id = g_delta_type and abs(t.value - s.value) >= h.value ))) where ( s.id is null or not h.id is null or ( l.type_id = g_uptime_policy and t.value < s.value ) or ( l.type_id = g_default_policy and t.value <> s.value ) ) and t.param_id <> g_ifName_parameter ); -- ae_state merge into ae_state d using ( select t.param_id, t.value, r.id res_id from ae_state_tmp t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) where t.param_id <> g_ifName_parameter ) s on (d.res_id = s.res_id and d.param_id = s.param_id) when matched then update set d.value = s.value , d.datetime = current_timestamp when not matched then insert (id, param_id, res_id, value) values (ae_state_seq.nextval, s.param_id, s.res_id, s.value); -- commit write nowait; end; end ae_monitoring; /
Javaã³ãŒã
private final static int BULK_SIZE = 200; private final static String INS_VAL_SQL = "insert into ae_state_tmp(id, device_id, profile_id, param_id, num, value) values (?,?,?,?,?,?)"; private final static String SAVE_VALUES_SQL = "begin ae_monitoring.saveValues; end;"; private void test_temporary() throws SQLException { System.out.println("test_temporary:"); CallableStatement st = c.prepareCall(INS_VAL_SQL); Long timestamp = System.currentTimeMillis(); Long uptime = 0L; Long inoct = 0L; Long ix = 1L; int bulk = BULK_SIZE; try { for (int i = 1; i <= ALL_SIZE; i++) { // uptime st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, UPTIME_PARAM_ID); st.setString(5, FAKE_NUM_VALUE); st.setString(6, uptime.toString()); st.addBatch(); // st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, IFNAME_PARAM_ID); st.setString(5, Integer.toString((i % 100) + 1)); st.setString(6, Integer.toString((i % 100) + 1)); st.addBatch(); // st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, INOCT_PARAM_ID); st.setString(5, Integer.toString((i % 100) + 1)); st.setString(6, inoct.toString()); st.addBatch(); if (--bulk <= 0) { st.executeBatch(); bulk = BULK_SIZE; } // uptime += 100L; if (uptime >= 1000) { uptime = 0L; } inoct += 10L; } if (bulk < BULK_SIZE) { st.executeBatch(); } } finally { st.close(); } Long delta_1 = System.currentTimeMillis() - timestamp; System.out.println((ALL_SIZE * 1000L) / delta_1); timestamp = System.currentTimeMillis(); st = c.prepareCall(SAVE_VALUES_SQL); timestamp = System.currentTimeMillis(); try { st.execute(); } finally { st.close(); } Long delta_2 = System.currentTimeMillis() - timestamp; System.out.println(delta_2); System.out.println((ALL_SIZE * 1000L) / (delta_1 - delta_2)); }
ãã®ã³ãŒããå®è¡ããŠãå®è¡ããŠååŸããŸãã
java.sql.SQLException: ORA-30926: ORA-06512: "AIS.AE_MONITORING", line 205 ORA-06512: line 1
èããŠã¿ããšããã®ãšã©ãŒã®çç±ãæããã«ãªããŸãã åŠçãããããŒã¿ã®ã»ããã«ãããã€ãã®å€æ°ã®ç«¶åããããŒã¿ãå«ãŸããŠããå ŽåïŒäœåããããèªã¿åã£ãïŒãåé¡ãçºçããŸãã SNMPç£èŠã®éåžžã®æ©èœã§ã¯ããã®ç¶æ³ã¯çºçããŸããããçºçããå Žåã«ã¢ããªã±ãŒã·ã§ã³ãã¯ã©ãã·ã¥ããã®ãé²ãããã«äœããæäŸããå¿ èŠããããŸãã
æåã«æãæµ®ãã¶ã®ã¯ãåå€æ°ã®éèšããŒã¿ãä¿åããããšã§ãã ãŸã ãªãå Žåã¯æ°ããã¬ã³ãŒããè¿œå ããããæ¢åã®ã¬ã³ãŒããæŽæ°ããæ°ããå€ãæžã蟌ã¿ãŸãã
Javaã³ãŒã
private final static int BULK_SIZE = 200; private final static String MERGE_VAL_SQL = "merge into ae_state_tmp d " + "using ( select ? id,? device_id,? profile_id,? param_id,? num,? value " + " from dual" + " ) s " + "on ( d.device_id = s.device_id and d.profile_id = s.profile_id and " + " d.param_id = s.param_id and d.num = s.num ) " + "when matched then " + " update set d.value = s.value " + "when not matched then " + " insert (id, device_id, profile_id, param_id, num, value) " + " values (s.id, s.device_id, s.profile_id, s.param_id, s.num, s.value)"; private final static String SAVE_VALUES_SQL = "begin ae_monitoring.saveValues; end;"; private void test_temporary() throws SQLException { System.out.println("test_temporary:"); CallableStatement st = c.prepareCall(MERGE_VAL_SQL); ...
çŸåšãåãåé¡ã«å¯ŸåŠããŠããŸãããããããªã¯ãšã¹ãã®æ®µéã§ïŒ
java.sql.BatchUpdateException: ORA-00600: , : [6704], [2], [0], [6301696], [], [], [], [], [], [], [], []
ç§ã¯ããããæŸæ£ããªããã°ãªããŸããïŒ
private final static int BULK_SIZE = 1;
çµæã¯èããæ¹åãããŸããïŒ
çµæ
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.00 0.00 0 0 0 0 Execute 1001 1.02 1.01 0 9002 3503 3001 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1003 1.02 1.01 0 9002 3503 3001 Misses in library cache during parse: 1 Misses in library cache during execute: 1 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 1002 0.00 0.00 SQL*Net message from client 1002 0.00 0.41 log file sync 1 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 23 0.01 0.01 0 1 0 0 Execute 23 0.21 0.21 43 29392 348 111 Fetch 11 0.00 0.00 0 27 0 10 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 57 0.22 0.23 43 29420 348 121 Misses in library cache during parse: 8 Misses in library cache during execute: 6 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ db file sequential read 41 0.01 0.01 db file scattered read 1 0.00 0.00
代æ¿ã¢ãããŒãïŒåå¥ïŒ
倧éåŠç段éã§ã°ã«ãŒãåãè¿œå ããããšã«ãããããŒã¿æ¿å ¥ã®æ®µéã§ïŒORA-600æ©èœãåãé€ããšåæã«ïŒäœæ¥ãç°¡çŽ åã§ããŸãã ãã®å ŽåãBULK_SIZEãæ¥ãããããå±ã«ãããæ倧ã«èšå®ããŸãã
PL / SQLã³ãŒã
CREATE OR REPLACE package AIS.ae_monitoring as procedure saveValuesDistinct; end ae_monitoring; / CREATE OR REPLACE package body AIS.ae_monitoring as g_ifName_parameter constant number default 103; g_default_policy constant number default 1; g_uptime_policy constant number default 2; g_threshold_policy constant number default 3; g_increase_type constant number default 1; g_decrease_type constant number default 2; g_delta_type constant number default 3; procedure saveValuesDistinct as begin -- , merge into ae_resource d using ( select t.id, t.device_id, t.num, t.value name, p.type_id, o.id owner_id from ( select device_id, profile_id, param_id, num , max(id) keep (dense_rank last order by datetime) id , max(value) keep (dense_rank last order by datetime) value , max(datetime) datetime from ae_state_tmp group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource_type r on (r.id = p.type_id) left join ae_resource o on (o.device_id = t.device_id and o.type_id = r.owner_id) where t.param_id = g_ifName_parameter ) s on ( d.device_id = s.device_id and d.res_num = s.num and d.type_id = s.type_id and d.start_date <= sysdate and sysdate <= nvl(d.end_date, sysdate + 1) ) when matched then update set d.tmp_id = s.id where d.name <> s.name when not matched then insert (id, device_id, owner_id, type_id, res_num, name) values (ae_resource_seq.nextval, s.device_id, s.owner_id, s.type_id, s.num, s.name); -- ae_resource insert into ae_resource(id, device_id, owner_id, type_id, res_num, name) select ae_resource_seq.nextval, t.device_id, o.id, p.type_id, t.num, t.value from ( select device_id, profile_id, param_id, num , max(id) keep (dense_rank last order by datetime) id , max(value) keep (dense_rank last order by datetime) value , max(datetime) datetime from ae_state_tmp group by device_id, profile_id, param_id, num ) t inner join ae_resource c on (c.tmp_id = t.id) inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource_type r on (r.id = p.type_id) left join ae_resource o on (o.device_id = t.device_id and o.type_id = r.owner_id); -- update ae_resource set end_date = sysdate , tmp_id = null where tmp_id > 0; -- ae_state_log insert into ae_state_log(id, res_id, param_id, value) select ae_state_log_seq.nextval, id, param_id, value from ( select distinct r.id, t.param_id, decode(l.type_id, g_uptime_policy, nvl(s.value, t.value), t.value) value from ( select device_id, profile_id, param_id, num , max(id) keep (dense_rank last order by datetime) id , max(value) keep (dense_rank last order by datetime) value , max(datetime) datetime from ae_state_tmp group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) left join ae_state s on (s.res_id = r.id and s.param_id = t.param_id) inner join ae_parameter a on (a.id = p.param_id) inner join ae_domain d on (d.id = a.domain_id) inner join ae_state_policy l on (l.id = d.policy_id) left join ae_threshold h on ( h.policy_id = l.id and (( h.type_id = g_increase_type and s.value <= h.value and t.value >= h.value ) or ( h.type_id = g_decrease_type and s.value >= h.value and t.value <= h.value ) or ( h.type_id = g_delta_type and abs(t.value - s.value) >= h.value ))) where ( s.id is null or not h.id is null or ( l.type_id = g_uptime_policy and t.value < s.value ) or ( l.type_id = g_default_policy and t.value <> s.value ) ) and t.param_id <> g_ifName_parameter ); -- ae_state merge into ae_state d using ( select t.param_id, t.value, r.id res_id from ( select device_id, profile_id, param_id, num , max(id) keep (dense_rank last order by datetime) id , max(value) keep (dense_rank last order by datetime) value , max(datetime) datetime from ae_state_tmp group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) where t.param_id <> g_ifName_parameter ) s on (d.res_id = s.res_id and d.param_id = s.param_id) when matched then update set d.value = s.value , d.datetime = current_timestamp when not matched then insert (id, param_id, res_id, value) values (ae_state_seq.nextval, s.param_id, s.res_id, s.value); -- commit write nowait; end; end ae_monitoring; /
Javaã³ãŒã
private final static int BULK_SIZE = 200; private final static String INS_VAL_SQL = "insert into ae_state_tmp(id, device_id, profile_id, param_id, num, value) values (?,?,?,?,?,?)"; private final static String SAVE_VALUES_DISTINCT_SQL = "begin ae_monitoring.saveValuesDistinct; end;"; private void test_temporary_distinct() throws SQLException { System.out.println("test_temporary:"); CallableStatement st = c.prepareCall(INS_VAL_SQL); Long timestamp = System.currentTimeMillis(); Long uptime = 0L; Long inoct = 0L; Long ix = 1L; int bulk = BULK_SIZE; try { for (int i = 1; i <= ALL_SIZE; i++) { // uptime st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, UPTIME_PARAM_ID); st.setString(5, FAKE_NUM_VALUE); st.setString(6, uptime.toString()); st.addBatch(); // st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, IFNAME_PARAM_ID); st.setString(5, Integer.toString((i % 100) + 1)); st.setString(6, Integer.toString((i % 100) + 1)); st.addBatch(); // st.setLong(1, ix++); st.setLong(2, DEVICE_ID); st.setLong(3, PROFILE_ID); st.setLong(4, INOCT_PARAM_ID); st.setString(5, Integer.toString((i % 100) + 1)); st.setString(6, inoct.toString()); st.addBatch(); if (--bulk <= 0) { st.executeBatch(); bulk = BULK_SIZE; } // uptime += 100L; if (uptime >= 1000) { uptime = 0L; } inoct += 10L; } if (bulk < BULK_SIZE) { st.executeBatch(); } } finally { st.close(); } Long delta_1 = System.currentTimeMillis() - timestamp; System.out.println((ALL_SIZE * 1000L) / delta_1); timestamp = System.currentTimeMillis(); st = c.prepareCall(SAVE_VALUES_DISTINCT_SQL); timestamp = System.currentTimeMillis(); try { st.execute(); } finally { st.close(); } Long delta_2 = System.currentTimeMillis() - timestamp; System.out.println(delta_2); System.out.println((ALL_SIZE * 1000L) / (delta_1 - delta_2)); }
èµ·åããŠçµæã確èªããŸãã
çµæ
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 2 0.00 0.00 0 0 0 0 Execute 1001 0.36 0.33 0 96 6616 3001 Fetch 0 0.00 0.00 0 0 0 0 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 1003 0.36 0.33 0 96 6616 3001 Misses in library cache during parse: 2 Misses in library cache during execute: 1 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 1002 0.00 0.00 SQL*Net message from client 1002 0.00 0.41 log file sync 1 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 30 0.01 0.01 0 3 0 0 Execute 30 0.41 0.40 3 48932 1104 218 Fetch 8 0.00 0.00 0 176 0 8 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 68 0.44 0.43 3 49111 1104 226 Misses in library cache during parse: 8 Misses in library cache during execute: 7 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ db file sequential read 3 0.00 0.00
äºæ³ã©ãããããŒã¿ãæ¿å ¥ããã³ã¹ãã¯æžå°ããŸãããããã®åŸã®åŠçã¯ããè€éã«ãªããŸããã
ã³ã¬ã¯ã·ã§ã³ã䜿çšããŸãïŒã³ã¬ã¯ã·ã§ã³ïŒ
DenKrepãæ£ããè¿°ã¹ãããã«ãããŒã¿ãæ¿å ¥ããã³ã¹ããå¯èœãªéãäœãããŠããGTTã¢ãããŒãã¯ç©ºãã空ãžæ³šãããã»ã¹ã«éåžžã«äŒŒãŠããŸããä»ã«ã©ã®ããã«ãããã¯ãŒãã³ã°ã®ã³ã¹ããåæžã§ããŸããïŒJDBCãããã䜿çšããŠPL / SQLã³ãŒããåŒã³åºãããšã¯ã§ããŸããïŒãŸãã¯ãã§ããŸãããã¡ãªããã¯ãããŸããïŒããé åãæž¡ãããšã¯ã§ããŸãïŒ
Javaã³ãŒãèªäœããé åãæž¡ãããã»ã¹ã«ã€ããŠã¯ããã®ã¬ã€ãã§è©³ãã説æããŠããŸããããŒã¿ã転éããã«ã¯ã次ã®ã¿ã€ãã決å®ããå¿ èŠããããŸãã
create or replace type ae_state_rec as object ( device_id number, profile_id number, param_id number, num varchar2(300), value varchar2(300) ) / create or replace type ae_state_tab as table of ae_state_rec; /
Oracle Client 11gãã€ã³ã¹ããŒã«ãããŠããããã[ORACLE_HOME] /jdbc/lib/classes12.zipã[ORACLE_HOME] /jdbc/lib/ojdbc5.jarã«çœ®ãæããå¿ èŠããããŸããããŸããã¢ããªã±ãŒã·ã§ã³ã®èµ·åæã«[ORACLE_HOME] /jdbc/lib/nls_charset12.zipã䜿çšå¯èœã§ãªããã°ãªããªãããšã匷調ããããšæããŸãã
ãµãŒããŒã§ã¢ã¬ã€ãã©ã®ããã«åŠçããŸããïŒéå§ããã«ã¯ãåã«ã«ãŒãã§äœæãããaddValueãåŒã³åºããŠã¿ãŠãã ããã
... procedure addValues( p_tab in ae_state_tab ) as begin for i in 1 .. p_tab.count loop addValue( p_device => p_tab(i).device_id , p_profile => p_tab(i).profile_id , p_param => p_tab(i).param_id , p_num => p_tab(i).num , p_val => p_tab(i).value ); end loop; commit write nowait; end; ...
Javaã³ãŒãã¯èããè€éã§ãã
Javaã³ãŒã
private final static String ADD_VALUES_SQL = "begin ae_monitoring.addValues(?); end;"; private void test_collection() throws SQLException { System.out.println("test_collection:"); OracleCallableStatement st = (OracleCallableStatement)c.prepareCall(ADD_VALUES_SQL); int oracleId = CharacterSet.CL8MSWIN1251_CHARSET; CharacterSet charSet = CharacterSet.make(oracleId); Long timestamp = System.currentTimeMillis(); Long uptime = 0L; Long inoct = 0L; RecType r[] = new RecType[ALL_SIZE * 3]; int ix = 0; for (int i = 1; i <= ALL_SIZE; i++) { // uptime r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(UPTIME_PARAM_ID), new CHAR(FAKE_NUM_VALUE, charSet), new CHAR(uptime.toString(), charSet)); // r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(IFNAME_PARAM_ID), new CHAR(Integer.toString((i % 100) + 1), charSet), new CHAR(Integer.toString((i % 100) + 1), charSet)); // r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(INOCT_PARAM_ID), new CHAR(Integer.toString((i % 100) + 1), charSet), new CHAR(inoct.toString(), charSet)); // uptime += 100L; if (uptime >= 1000) { uptime = 0L; } inoct += 10L; } RecTab t = new RecTab(r); try { st.setORAData(1, t); st.execute(); } finally { st.close(); } System.out.println((ALL_SIZE * 1000L) / (System.currentTimeMillis() - timestamp)); }
ã¯ã©ã€ã¢ã³ãããã®é åã®è»¢éã«é¢é£ãããã¬ãŒã¹ã«ã¯ãããŸããŸãªé¢çœãæŒç®åã衚瀺ãããŸãã
SELECT INSTANTIABLE, supertype_owner, supertype_name, LOCAL_ATTRIBUTES FROM all_types WHERE type_name = :1 AND owner = :2
çµæã¯è«ççã§ãïŒ
çµæ
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 4 0.00 0.00 0 0 0 0 Execute 4 4.35 4.31 5 136053 6610 3 Fetch 1 0.00 0.00 0 9 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 9 4.35 4.31 5 136062 6610 4 Misses in library cache during parse: 2 Misses in library cache during execute: 2 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 6 0.00 0.00 SQL*Net message from client 6 0.23 0.34 SQL*Net more data from client 41 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 77 0.00 0.00 0 0 0 0 Execute 17270 2.97 2.92 5 6046 6610 3160 Fetch 14013 0.49 0.49 1 129930 0 13909 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 31360 3.48 3.43 6 135976 6610 17069 Misses in library cache during parse: 8 Misses in library cache during execute: 11 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ db file sequential read 6 0.00 0.00
ã¯ã©ã€ã¢ã³ãããã®ããŒã¿è»¢éã«é¢é£ããã€ã³ãžã±ãŒã¿ã¯æ¹åãããŸããããããŒã¿åŠçã¯plsqlãªãã·ã§ã³ã«æ¯ã¹ãŠããè€éã«ãªããŸããã
è³¢ãã³ã¬ã¯ã·ã§ã³ã䜿çšããŸãïŒãã«ã¯ïŒ
æããã«ãã¯ã©ã€ã¢ã³ãããéä¿¡ãããé åã®å¯èœæ§ãå®å šã«å©çšããŠããããã§ã¯ãããŸãããé åãSQLã¯ãšãªã«çŽæ¥æž¡ããŠäžæ¬åŠçãæå¹ã«ãããšäŸ¿å©ã§ããããã®æ¹æ³ã¯ïŒã¯ãšãªãè€éããããããBULK COLLECTã䜿çšã§ããŸããã幞ããªããšã«ãã³ã¬ã¯ã·ã§ã³ãTABLEã§ã©ããã§ããŸãã
PL / SQLã³ãŒã
CREATE OR REPLACE package AIS.ae_monitoring as procedure saveValues( p_tab in ae_state_tab ); end ae_monitoring; / CREATE OR REPLACE package body AIS.ae_monitoring as g_ifName_parameter constant number default 103; g_default_policy constant number default 1; g_uptime_policy constant number default 2; g_threshold_policy constant number default 3; g_increase_type constant number default 1; g_decrease_type constant number default 2; g_delta_type constant number default 3; procedure saveValues( p_tab in ae_state_tab ) as begin -- , merge into ae_resource d using ( select t.device_id, t.num, t.value name, p.type_id, o.id owner_id from ( select device_id, profile_id, param_id, num , max(value) value from table( p_tab ) group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource_type r on (r.id = p.type_id) left join ae_resource o on (o.device_id = t.device_id and o.type_id = r.owner_id) where t.param_id = g_ifName_parameter ) s on ( d.device_id = s.device_id and d.res_num = s.num and d.type_id = s.type_id and d.start_date <= sysdate and sysdate <= nvl(d.end_date, sysdate + 1) ) when not matched then insert (id, device_id, owner_id, type_id, res_num, name) values (ae_resource_seq.nextval, s.device_id, s.owner_id, s.type_id, s.num, s.name); -- ae_state_log insert into ae_state_log(id, res_id, param_id, value) select ae_state_log_seq.nextval, id, param_id, value from ( select distinct r.id, t.param_id, decode(l.type_id, g_uptime_policy, nvl(s.value, t.value), t.value) value from ( select device_id, profile_id, param_id, num , max(value) value from table( p_tab ) group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) left join ae_state s on (s.res_id = r.id and s.param_id = t.param_id) inner join ae_parameter a on (a.id = p.param_id) inner join ae_domain d on (d.id = a.domain_id) inner join ae_state_policy l on (l.id = d.policy_id) left join ae_threshold h on ( h.policy_id = l.id and (( h.type_id = g_increase_type and s.value <= h.value and t.value >= h.value ) or ( h.type_id = g_decrease_type and s.value >= h.value and t.value <= h.value ) or ( h.type_id = g_delta_type and abs(t.value - s.value) >= h.value ))) where ( s.id is null or not h.id is null or ( l.type_id = g_uptime_policy and t.value < s.value ) or ( l.type_id = g_default_policy and t.value <> s.value ) ) and t.param_id <> g_ifName_parameter ); -- ae_state merge into ae_state d using ( select t.param_id, t.value, r.id res_id from ( select device_id, profile_id, param_id, num , max(value) value from table( p_tab ) group by device_id, profile_id, param_id, num ) t inner join ae_profile_detail p on (p.profile_id = t.profile_id and p.param_id = t.param_id) inner join ae_resource r on ( r.device_id = t.device_id and r.res_num = t.num and r.type_id = p.type_id and r.start_date <= sysdate and sysdate <= nvl(r.end_date, sysdate + 1)) where t.param_id <> g_ifName_parameter ) s on (d.res_id = s.res_id and d.param_id = s.param_id) when matched then update set d.value = s.value , d.datetime = current_timestamp when not matched then insert (id, param_id, res_id, value) values (ae_state_seq.nextval, s.param_id, s.res_id, s.value); -- commit write nowait; end; end ae_monitoring; /
Javaã³ãŒã
private final static String BULK_VALUES_SQL = "begin ae_monitoring.saveValues(?); end;"; private void test_bulk() throws SQLException { System.out.println("test_bulk:"); OracleCallableStatement st = (OracleCallableStatement)c.prepareCall(BULK_VALUES_SQL); int oracleId = CharacterSet.CL8MSWIN1251_CHARSET; CharacterSet charSet = CharacterSet.make(oracleId); Long timestamp = System.currentTimeMillis(); Long uptime = 0L; Long inoct = 0L; RecType r[] = new RecType[ALL_SIZE * 3]; int ix = 0; for (int i = 1; i <= ALL_SIZE; i++) { // uptime r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(UPTIME_PARAM_ID), new CHAR(FAKE_NUM_VALUE, charSet), new CHAR(uptime.toString(), charSet)); // r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(IFNAME_PARAM_ID), new CHAR(Integer.toString((i % 100) + 1), charSet), new CHAR(Integer.toString((i % 100) + 1), charSet)); // r[ix++] = new RecType( new NUMBER(DEVICE_ID), new NUMBER(PROFILE_ID), new NUMBER(INOCT_PARAM_ID), new CHAR(Integer.toString((i % 100) + 1), charSet), new CHAR(inoct.toString(), charSet)); // uptime += 100L; if (uptime >= 1000) { uptime = 0L; } inoct += 10L; } RecTab t = new RecTab(r); try { st.setORAData(1, t); st.execute(); } finally { st.close(); } System.out.println((ALL_SIZE * 1000L) / (System.currentTimeMillis() - timestamp)); }
çµæã¯ããèªèº«ãç©èªã£ãŠããŸãïŒ
çµæ
OVERALL TOTALS FOR ALL NON-RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 4 0.00 0.00 0 0 0 0 Execute 4 0.20 0.20 4 696 1095 3 Fetch 1 0.00 0.00 0 9 0 1 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 9 0.20 0.20 4 705 1095 4 Misses in library cache during parse: 0 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ SQL*Net message to client 6 0.00 0.00 SQL*Net message from client 6 0.10 0.19 SQL*Net more data from client 41 0.00 0.00 OVERALL TOTALS FOR ALL RECURSIVE STATEMENTS call count cpu elapsed disk query current rows ------- ------ -------- ---------- ---------- ---------- ---------- ---------- Parse 30 0.00 0.00 0 0 0 0 Execute 38 0.18 0.17 4 591 1095 217 Fetch 46 0.00 0.00 0 96 0 30 ------- ------ -------- ---------- ---------- ---------- ---------- ---------- total 114 0.18 0.18 4 687 1095 247 Misses in library cache during parse: 7 Misses in library cache during execute: 7 Elapsed times include waiting on following events: Event waited on Times Max. Wait Total Waited ---------------------------------------- Waited ---------- ------------ db file sequential read 4 0.00 0.00
çµè«
ãã¹ãçµæã瀺ãããã«ãã¯ã©ã€ã¢ã³ãã³ãŒãïŒãã«ã¯ïŒããOracleãžã®é åã®çŽæ¥è»¢éã«ãããæé«ã®ããã©ãŒãã³ã¹ãå®çŸã§ããŸããGTTïŒäžæçãåå¥ïŒã䜿çšããããªã¢ã³ãã¯ãããã©ãŒãã³ã¹ã®ç¹ã§ã¯ããã»ã©å£ããŸããããJavaã³ãŒãã®èŠ³ç¹ããã¯ã¯ããã«åçŽã§ããããã«ãäžæãªãã·ã§ã³ã䜿çšãããšãããããšæã®é 眮ãäžé©åãªå Žåã«ORA-600ã芳å¯ã§ããŸãã
ããŒã¿åŠçã«äœ¿çšããã¢ãããŒãã¯ãŠãŒã¶ãŒæ¬¡ç¬¬ã§ãããã¹ãçµæã¯GitHubã«æçš¿ãããŸãã