Slow write to tag script

Hi all!
we have 1 Siemens S7-1500 connected trough OPC UA, the PLC is managing 3 lines. every line has 100 db and in every db there are 14 elements (strings and Integer).
so there are 300 DB, every DB is updating every 7seconds and set a tag to 1. We have tag change value script on every trigger tag (300 tag change valus script). The script in the tag calls a shared script that calls a Store procedure, every line has its own store procedure so the tag change script send the tagPath and the name of the line. we are logging on logs in the server in 1 of these script, but the difference between the script is fired until the script writes back 0 to the trigger is about 350ms. the last line of the script is system.tag.write(tagpath,0) but the status of the wirte
is 2 (pending). this time can be up to 15 seconds. sometimes more. The PLC write it self to 0 after 50s if Ignition doesnt and it happens every 2 or 3 minutes.
we see on threads
gateway-tags-eventscripts-3, id=420725 (see attached picture)

this is the shared script

def save2(tagPath, factory):
	logger = system.util.getLogger("Traceability")
	now = system.db.dateFormat(system.date.now(), 'yyyy-MM-dd HH:mm:ss.SSS')
	logger.info('now1:'+now)
	if factory == 'core':
		storeProcedure="saveCore"
	elif factory == 'mold':
		storeProcedure="saveMold"
	elif factory == 'meltLine':
		storeProcedure ="saveMelt" 
	elif factory == 'finishing':
		storeProcedure ="saveFinishing" 
	folderPath = tagPath[:tagPath.rfind("/")]
	tags = system.tag.browseTags(parentPath=folderPath)
	call = system.db.createSProcCall(storeProcedure, "foqus")
	call.registerReturnParam(system.db.VARCHAR)
	for tag in tags:
		argument = tag.name
		value = system.tag.read(tag.fullPath).value
		if argument!='handshake' and argument!='readTrigger':
			if str(tag.dataType) == 'Int4' or str(tag.dataType) == 'Int2':
				dataType=system.db.INTEGER
			elif str(tag.dataType) == 'String':
				dataType=system.db.VARCHAR
			call.registerInParam(argument, dataType , value)
	now2 = system.db.dateFormat(system.date.now(), 'yyyy-MM-dd HH:mm:ss.SSS')
	logger.info('now2:'+now2)
	system.db.execSProcCall(call)
	now3=1
	now3 = call.getReturnValue()
	logger.info('now3:'+now3)	
	if tagPath.find('handshake')>-1 or tagPath.find('readTrigger')>-1:
			result = system.tag.write(tagPath,0)
			logger.info('tag:'+str(result))

we are missing some events as well but I guess it is related to this problem
any tips or advices?

from the logs:

Traceability 12Nov2019 15:34:53 tag:2
Traceability 12Nov2019 15:34:53 now3:5
Traceability 12Nov2019 15:34:53 now2:2019-11-12 15:34:53.740
Traceability 12Nov2019 15:34:53 now1:2019-11-12 15:34:53.702
Traceability 12Nov2019 15:34:53 now0:2019-11-12 15:34:53.702

now 0 comes from the script on the tag change, and tag:2 comes from the shared script after the system.tag.write where 2 is the return value of the system.write.tag
i am as well loging the trigger tag and I can see on easychart that from it goes to 1 until I get the first log from the tag change value in the log server are 2 second diffrence

Hi, I have similar problem, did you manage to understand what was slowing things down for you ?

We did 2 changes.
1 was in the database, we apply some indexes as the store procedure was looking for string on tables with more 1 million values.

2 we update to ignition 8. And we use async to write to the tags. And we use reference tags as well. We never found the problem but this 2 things improve the system and we stop getting blocked scripts.