- Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathpipelining-and-async.cs
105 lines (85 loc) · 4.2 KB
/
pipelining-and-async.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
usingOracle.ManagedDataAccess.Client;
usingSystem.Threading.Tasks;
usingSystem.Threading;
usingSystem;
// This code sample demonstrates using asynchronous ODP.NET (managed or core) with pipelining.
// It times opening a connection and several query executions.
// To run this app, add your database's HR schema User Id, Password, and Data Source values
// with ODP.NET 23ai or higher connecting to an Oracle Database 23ai or higher.
classODPNET_Async_Pipelining
{
publicstaticasyncTaskMain()
{
// Add password and data source to connect to your Oracle database
stringconString="User Id=hr;Password=<PASSWORD>;Data Source=<DATA SOURCE>;";
//Enable pipelining
OracleConfiguration.Pipelining=true;
using(OracleConnectioncon=newOracleConnection(conString))
{
stringcmdText1="SELECT * FROM EMPLOYEES";
stringcmdText2="SELECT * FROM DEPARTMENTS";
stringcmdText3="SELECT * FROM JOBS";
OracleCommandcmd1=newOracleCommand(cmdText1,con);
OracleCommandcmd2=newOracleCommand(cmdText2,con);
OracleCommandcmd3=newOracleCommand(cmdText3,con);
// Measure how long async connection open takes
DateTimestart_time=DateTime.Now;
Tasktask=con.OpenAsync();
DateTimeend_time_open=DateTime.Now;
// Simulate an operation that takes one second
Thread.Sleep(1000);
// Retrieve open connection with "await"
awaittask;
// Measure time for asynchronous query execution calls
DateTimestart_time_query=DateTime.Now;
Tasktask1=cmd1.ExecuteNonQueryAsync();
Tasktask2=cmd2.ExecuteNonQueryAsync();
Tasktask3=cmd3.ExecuteNonQueryAsync();
// Measure time async query initiations took
DateTimeend_time_query=DateTime.Now;
// Simulate an operation that takes one second
Thread.Sleep(1000);
awaittask1;
awaittask2;
awaittask3;
// Measure time all the async operations took plus sleep time
DateTimeend_time_all=DateTime.Now;
// Calculate connection open time
TimeSpants_open=end_time_open-start_time;
doublets_open1=Math.Round(ts_open.TotalSeconds,2);
Console.WriteLine("Asynchronous connection open time: "+ts_open1+" seconds");
// Calculate queries initiation time
TimeSpants_initiate_sql=end_time_query-start_time_query;
doublets_sql1=Math.Round(ts_initiate_sql.TotalSeconds,2);
Console.WriteLine("Asynchronous and pipelining query initiation time: "+ts_sql1+" seconds");
// Calculate SQL executions time
TimeSpants_sql=end_time_all-start_time_query;
doublets_sql2=Math.Round(ts_sql.TotalSeconds,2);
Console.WriteLine("Asynchronous and pipelining query execution time: "+ts_sql2+" seconds");
// Calculate overall ODP.NET operation time
TimeSpants_all=end_time_all-start_time;
doublets_all1=Math.Round(ts_all.TotalSeconds,2);
Console.WriteLine("Asynchronous and pipelining operations total time: "+ts_all1+" seconds");
cmd1.Dispose();
cmd2.Dispose();
cmd3.Dispose();
}
}
}
/* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved. */
/******************************************************************************
*
* You may not use the identified files except in compliance with The MIT
* License (the "License.")
*
* You may obtain a copy of the License at
* https://github.com/oracle/Oracle.NET/blob/master/LICENSE
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*
*****************************************************************************/