Skip to content

Commit

Permalink
Switch back to use bulk values
Browse files Browse the repository at this point in the history
  • Loading branch information
TimEvens committed Mar 31, 2021
1 parent f87fc6b commit a852c5c
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 275 deletions.
23 changes: 15 additions & 8 deletions src/main/java/org/openbmp/WriterRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,25 +94,32 @@ public void run() {

StringBuilder query = new StringBuilder();

// Loop through queries and add them as multi-statements
// Loop through queries and add as unique values to map, replacing duplicate (state compression)
for (Map.Entry<String, LinkedList<String>> entry : bulk_query.entrySet()) {
String key = entry.getKey().toString();

String[] ins = key.split("[|]");
query.append(ins[0]); // Insert statement

boolean first = true;
for (String value : entry.getValue()) {

if (query.length() > 0)
query.append(';');
if (first) {
first = false;
} else {
query.append(',');
}

query.append(ins[0]);
query.append(' ');
query.append(value);
query.append(' ');

if (ins.length > 1 && ins[1] != null && ins[1].length() > 0)
query.append(ins[1]);
}

// Ending suffix statement, such as on conflict
if (ins.length > 1 && ins[1] != null && ins[1].length() > 0)
query.append(ins[1]);

query.append(';');

}

if (query.length() > 0) {
Expand Down
13 changes: 6 additions & 7 deletions src/main/java/org/openbmp/psqlquery/BaseAttributeQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ public String[] genInsertStatement() {
final String [] stmt = { " INSERT INTO base_attrs (hash_id,peer_hash_id,origin,as_path,origin_as,next_hop,med,local_pref," +
"isAtomicAgg,aggregator,community_list,ext_community_list,large_community_list," +
"cluster_list,originator_id,as_path_count,nexthop_isIPv4,timestamp)" +
// " VALUES ",
"SELECT DISTINCT ON (hash_id) * FROM ( VALUES ",

" VALUES ",
// "SELECT DISTINCT ON (hash_id) * FROM ( VALUES ",
//
// ") t(hash_id,peer_hash_id,origin,as_path,origin_as,next_hop,med,local_pref," +
// "isAtomicAgg,aggregator,community_list,ext_community_list,large_community_list," +
// "cluster_list,originator_id,as_path_count,nexthop_isIPv4,timestamp)" +
// " ORDER BY hash_id,timestamp desc" +
") t(hash_id,peer_hash_id,origin,as_path,origin_as,next_hop,med,local_pref," +
"isAtomicAgg,aggregator,community_list,ext_community_list,large_community_list," +
"cluster_list,originator_id,as_path_count,nexthop_isIPv4,timestamp)" +
" ORDER BY hash_id,timestamp desc" +
" ON CONFLICT (peer_hash_id,hash_id) DO UPDATE SET " +
"timestamp=excluded.timestamp" };
return stmt;
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/org/openbmp/psqlquery/UnicastPrefixQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public String[] genInsertStatement() {
"origin_as,prefix,prefix_len,prefix_bits,timestamp," +
"isWithdrawn,path_id,labels,isPrePolicy,isAdjRibIn) " +

" VALUES ",
// "SELECT DISTINCT ON (hash_id) * FROM ( VALUES ",
// ") t(hash_id,peer_hash_id,base_attr_hash_id,isIPv4," +
// "origin_as,prefix,prefix_len,prefix_bits,timestamp," +
// "isWithdrawn,path_id,labels,isPrePolicy,isAdjRibIn) " +
// " ORDER BY hash_id,timestamp desc" +
// " VALUES ",
"SELECT DISTINCT ON (hash_id) * FROM ( VALUES ",

") t(hash_id,peer_hash_id,base_attr_hash_id,isIPv4," +
"origin_as,prefix,prefix_len,prefix_bits,timestamp," +
"isWithdrawn,path_id,labels,isPrePolicy,isAdjRibIn) " +
" ORDER BY hash_id,timestamp desc" +
" ON CONFLICT (peer_hash_id,hash_id) DO UPDATE SET timestamp=excluded.timestamp," +
"base_attr_hash_id=CASE excluded.isWithdrawn WHEN true THEN ip_rib.base_attr_hash_id ELSE excluded.base_attr_hash_id END," +
"origin_as=CASE excluded.isWithdrawn WHEN true THEN ip_rib.origin_as ELSE excluded.origin_as END," +
Expand Down
143 changes: 0 additions & 143 deletions src/main/java/org/openbmp/psqlquery/oldLsLinkQuery.java

This file was deleted.

106 changes: 0 additions & 106 deletions src/main/java/org/openbmp/psqlquery/oldLsPrefixQuery.java

This file was deleted.

11 changes: 6 additions & 5 deletions src/main/resources/obmp-psql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ base:

# Number of seconds between rebalacing of writer threads
# Rebalance will drain writer queues at this interval if at least one writer is above threshold
writer_rebalance_seconds: 600
writer_rebalance_seconds: 480

# Maximum input queue size
# Normally within the range of 1000 - 20000 is enough
writer_queue_size: 3000
writer_queue_size: 2500

# Maximum input queue size for the consumer
# A good starting size is 2 times the size of the writer queue size
consumer_queue_size: 60000
consumer_queue_size: 30000

# By default AS Path indexing is enabled. This can be very resource intensive to psql
# and disk. You can disable updating the psql 'as_path_analysis' table if
Expand All @@ -65,10 +65,11 @@ postgres:

# The number of statements or records to batch in a single bulk update/insert/delete
# NOTE: It's more efficient to have more threads with a low batch size
batch_records: 300
batch_records: 500

# The time in milliseconds to wait for batching records in a bulk update/insert/delete
batch_time_millis: 100
# Note this will state compress records in this time period.
batch_time_millis: 200

# The number of times to retry a statement
retries: 10
Expand Down

0 comments on commit a852c5c

Please sign in to comment.