acquireLock() take too much time for executing

I have the functions databaseManager.acquireLock() and databaseManager.releaseAllLocks() in my edit-, save- and cancel record(s) method.
This is working well as expected in the local network. But for external clients, connected to the Servoy app server by a Internet connection, the time for executing the “edit” method with the acquire.Lock() function takes more than 15 seconds!?
The save and cancel methods with the releaseAllLocks() function is working fast on all connected smart clients.

How can I fix that issue?

Servoy 5.2.1
Mac OS X Server 10.6
Win 7, XP Clients
Java 1.6_20

How many records are locked on edit ?

Thomas,

What parameters do you pass to the acquireLock() call?

Rob

Hans Nieuwenhuis:
How many records are locked on edit ?

Hello Hans,
hello Rob,

good question(s)!

My global method for the record(s) lock is:

var lock = databaseManager.acquireLock(forms[vForm].foundset,0,vLockname);
if(lock)
return true

I will lock only the one current record in edit mode, but in my function I’m locking the whole foundset (this could be over 100.000 rows in db :x ).
Should I change the function to:

databaseManager.acquireLock(forms[vForm].controller.setSelectedIndex(forms[vForm].getSelectedIndex()),0,vLockname)

Does this function is working as expected?

tgs:
I will lock only the one current record in edit mode, but in my function I’m locking the whole foundset (this could be over 100.000 rows in db :x ).

Locking a foundset loads the entire foundset in memory to check if any records are locked by another client.

Rob

rgansevles:
Locking a foundset loads the entire foundset in memory to check if any records are locked by another client.

Ok, this can take a lot of time of course. But what do I have to do, if I would like to lock only the one current record that is in edit mode by the user?

Thomas

You can lock the current record. See sample in Servoy.

//locks the complete foundset
databaseManager.acquireLock(foundset,-1);

//locks the current row
databaseManager.acquireLock(foundset,0);

//locks the row with index 13 in the foundset
databaseManager.acquireLock(foundset,13);

//locks all related orders for the current Customer
var success = databaseManager.acquireLock(Cust_to_Orders,-1);
if(!success)

I often lock the parent of a group of records i want to lock (instead of locking the related records)
For instance put a lock on a specific order before editing the orderitems. If another user is editing ( and locked ) this order the new lock can not be acquired.

Thank you very much Hans!

I also took a look in to the sample code of the acquireLock() function and I thought the example:

//locks the current row
databaseManager.acquireLock(foundset,0);

would be my friend!?
Now I have changed my code a litte to:

function gm_lock_current_row(vForm,vRow,vLockName) {
	var vLock = databaseManager.acquireLock(forms[vForm].foundset,vRow,vLockName);
	if(vLock){
		return true;
	}
	else {
		globals.gm_showdialog_warning('i18n:dialog_message_locked_rec','OK',null,null,null);
		return false;
	}
}

and it’s working (fast) on my network. I will see what’s happen if I connect to the Servoy app server by the Internet.

tgs:
I will see what’s happen if I connect to the Servoy app server by the Internet.

No advantage with the modifyed code :( . Executing the acquireLock function takes 20 sec. while connected from the Internet.

Thomas

Did you check on the admin page that only 1 record is locked ?
B.t.w. what database are you using.

Hans Nieuwenhuis:
Did you check on the admin page that only 1 record is locked ?
B.t.w. what database are you using.

I’m seeing only one row in the servoy-admin Locks page. But I don’t know if <5.16205; locked by …> is one or many records? The number doesn’t change if I lock an other record in the same table.

The db I’m using is PostgreSQL 8.4.4.

Thomas

It seems only on record is locked.
If I rember correctly the number after the dot is the primary key of the locked record.
I suggest you build a small solution that only locks one record and does not do anything else.
See what that does. I can not imagine that locking one record takes that long.
Maybe something else in your solution takes long to execute ??

Regards,

Hello Hans,

I will make a try as you suggest, but when I comment out the acquireLock lines in the globale method, executing time is as fast as it should be.

Regards
Thomas

Then create a case for this in the servoy support system.
You can send them the smaal test solution

Regards,

Thomas,

What is the value of vRow?
A value of -1 also means that the entire foundset is locked.

Rob

rgansevles:
What is the value of vRow?
A value of -1 also means that the entire foundset is locked.

Hello Rob,

the value is: var vRow = controller.getSelectedIndex();
I have a form function “m_doEdit”:

function m_doEdit() {
	//check if current row is locked
	var vForm = controller.getName();
	var vRow = controller.getSelectedIndex();
	var vLockName = vForm + vRow;
	if(globals.gm_lock_current_row(vForm,vRow,vLockName)){
		//return 'true' locks the row of the foundset
      //my code
     }
}

The globale function is:

function gm_lock_current_row(vForm,vRow,vLockName) {
	// TODO Auto-generated method stub
	//locks the current row of vForm
	var vLock = databaseManager.acquireLock(forms[vForm].foundset,vRow,vLockName);
	if(vLock){
		return true;
	}
	else {
		globals.gm_showdialog_warning('i18n:dialog_message_locked_rec','OK',null,null,null);
		return false;
	}
}

At my first try of the lock functionality I used ‘0’ as value. Not ‘-1’ because the foundset could be thousands of records (rows).
Today I took a look on the servoy-admin. In ‘Locks’ are two entries for locked rows, but the clients doesn’t have locked the row(s) at the moment.

6.158404; locked by detlef@pc018[192.168.1.18:3001] (Servoy Smart Client) at Wed Sep 08 09:57:29 CEST 2010
6.158407; locked by Sandro@pc016[192.168.1.16:3003] (Servoy Smart Client) at Wed Sep 08 10:19:00 CEST 2010

I cannot release the two locks from the servoy-admin site. They are still in the list!?

When the clients fire the “save” or “cancel” functions in the soulution, the globale method will be executed:

function gm_unlock_current_row(vLockName) {
	// TODO Auto-generated method stub
	return(databaseManager.releaseAllLocks(vLockName))
}

I also have a server error log:

2010-09-08 10:08 RMI TCP Connection(121)-192.168.1.16 ERROR com.servoy.j2db.util.Debug Throwable
com.servoy.j2db.ApplicationException: Record is locked
at com.servoy.j2db.dataprocessing.Zu.performUpdates(Zu.java:744)
at sun.reflect.GeneratedMethodAccessor431.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:305)
at sun.rmi.transport.Transport$1.run(Transport.java:159)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:155)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:637)

What is wrong in my functions? Why takes executing the “edit” method with the lock function 20 sec. on a smart client, connected to the servoy app server over Internet?

I tried a lot to speed up the current record lock function for connected clients over the internet. Fireing only the acquireLock() without any other function doesn’t increase the speed, but when the servoy app server is connected to a database with only 1000 to 3000 rows (records), locking is pretty fast. If the server is connected to the customers database with hundred thousands of records the executing time for the acquireLock decreases to more than 15 seconds! Clients connected to the servoy app server over the internal network doesn’t have the speed problem!?
I’m wondering about this issue, because I’m locking only one row and not a foundset of the table.

Since I have upgraded from PostgreSQL 8.4.4 to 9.0.1 the acquireLock issue seems to be gone!
The function is from remote (http/vpn) as fast as on the internal network.

Thomas