Skip to content

Instantly share code, notes, and snippets.


Vladimir Sitnikov vlsi

View GitHub Profile
vlsi / build.gradle.kts
Last active Oct 7, 2020
Add Class-Path attribute to a jar manifest in Gradle
View build.gradle.kts
// Add Class-Path to the existing "jar" task
tasks.jar {
val classpath = configurations.runtimeClasspath
// Input declaration is needed for the proper up-to-date checks
manifest {
"Class-Path" to { cp -> cp.joinToString(" ") { it.absolutePath } }
vlsi /
Last active Apr 28, 2020
Publishing Gradle-based Java artifacts to a custom Nexus repository

Apache Maven enables developers to augment repository URL via settings.xml. That might sound powerful, however, it requires to use the same repository IDs across all the projects which might not be always possible.

Let's see how Gradle-based project can be published to a custom repository.

For instance, let's try to publish Apache Calcite to our own Nexus instance. Of course we don't want to commit the URL and password of our secretNexus to GitHub, so we need to augment the build without touching the files.

Gradle has Initialization Scripts that enable users to augment all the builds without touching project-specific files.


Keybase proof

I hereby claim:

  • I am vlsi on github.
  • I am vlsi ( on keybase.
  • I have a public key ASC2sRZGT4IKWFFWjBEznXZ8DHXjdgWnotEDW-x6_eLlYAo

To claim this, I am signing this object:

vlsi / hs_err_pid57596.log
Created Nov 4, 2017
shenandoah/jdk10 crash logs
View hs_err_pid57596.log
# A fatal error has been detected by the Java Runtime Environment:
# Internal Error (/Users/vladimirsitnikov/Documents/work/shenandoah/src/hotspot/share/opto/node.cpp:177), pid=57596, tid=27907
# assert(_refresh_tick < 2*100000) failed: DU iteration must converge quickly
# JRE version: OpenJDK Runtime Environment (10.0) (fastdebug build 10-internal+0-adhoc.vladimirsitnikov.shenandoah)
# Java VM: OpenJDK 64-Bit Server VM (fastdebug 10-internal+0-adhoc.vladimirsitnikov.shenandoah, mixed mode, tiered, compressed oops, g1 gc, bsd-amd64)
# No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
vlsi /
Created Feb 4, 2017
JTextArea append benchmark

According to the measurements, replaceRange + append works faster than setText except for the case when text is fully replaced. In 100% replace case setText is on par with replaceRange + append (the results are within error bounds).

For small appends there's a win in terms of response time and memory allocation.

# JMH 1.12 (released 309 days ago, please consider updating!)
# VM version: JDK 1.8.0_102, VM 25.102-b14
# VM invoker: /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home/jre/bin/java
vlsi / 01_init.sql
Last active Sep 8, 2016
PostgreSQL index only scan for expression testing
View 01_init.sql
drop table vlsi;
create table vlsi(pk int4, type numeric, vc varchar(500), num numeric);
insert into vlsi(pk, type,vc,num) select s.x, round(x/1000), md5('||x)||md5('||x+1)||md5(''||x+2), mod(x, 1000)
from generate_series(1,1000000) as s(x);
-- Several values exceeed 128 substr, so they require "table access"
insert into vlsi(pk, type,vc,num) select s.x+1000000, round(x/1000), lpad('a', 128, 'a')||'zxc'||s.x||'v', mod(x, 1000)
from generate_series(1,10) as s(x);
vlsi /
Last active Mar 7, 2018
JMeter suggestion: add comment that briefly describes test plan as an XML comment

Current JMeter's JMX files are not human-readable, and it is hard to review "diff" between two versions of a script.

I suggest adding a human-readable comment to the start of the file, so the diff between scripts can be easier to understand:

<?xml version="1.0" encoding="UTF-8"?>
Test plan:
   Thread group (146 threads, 1:00:00 duration)
      login (http sampler /login)
vlsi /
Last active Dec 11, 2020
The fastest way of string concatenation in Oracle PL/SQL

When builing large strings with lots of concatenations in PL/SQL, custom approach like "use varchar2(32000) buffer to reduce the number of dbms_lob calls" makes sense even for Oracle

The response time improvement is 4..300+ times :) depending on the DB version and API you use.

Note that simple v_clob || TO_CHAR (SYSTIMESTAMP) || ', ' ==> v_clob || TO_CLOB(TO_CHAR (SYSTIMESTAMP) || ', ') trick (note the extra to_clob) makes 24 times improvement for 11g. The trick is bad for 12c where results in 1.5x degradation.

The code was published 4 year ago as an answer to "How to Quickly Append VARCHAR2 to CLOB":

View PostgreSQL and JDBC: striving for high performance
Vladimir Sitnikov is currently working on performance and scalability of NetCracker OSS.
Telecommunication companies world wide use NetCracker OSS for enterprise and network automation.
Vladimir is keen on Java and database performance: Oracle, PostgreSQL. He’s one of the committers
in the PostgreSQL JDBC driver project, and architect of many performance improvements.
Common Java wisdom is to use PreparedStatements and Batch DML in order to achieve top performance.
It turns out one cannot just blindly follow the best practices. In order to get high throughput, you need
to understand the specifics of the database in question, and the content of the data.
vlsi / 01_plan_flipper.sql
Last active May 23, 2020
PostgreSQL plan flipper
View 01_plan_flipper.sql
-- This sample reproduces a bug of a "sudden" flip of a server-prepared statement in PG 9.2+
-- In this particular case, backend selects very bad index even though bind values are the same and the table is analyzed
TL;DR: if you want to know true execution plan for a query with bind variables, you must use "prepare...";
then repeat "explain analyze execute" 6 times :)
-- Note: do not confuse "5 executions before pgjdbc starts to use server-prepared statements" with
-- "first 5 executions of a server-prepared statement before plan flip"
-- Here's discussion in pgsql-hackers list: