Hi
I am creating a basic stock trading platform. My app has to deal with 1000s of incoming messages and for each message process and then update various windows (with price and qty etc). I have all the basic logic behind the app working, but I would like to improve the performance.
I understand that Threads along with Queues can be used to enhance my apps speed. But when I tried to implement both of these techniques it only seemed to slow things down even more. Please see below for a snippet of code from my app:
'Firstly I declare two queues
'Then I start two while loops on seperate threads, which will be used to
'remove items from each queue
'Each message that comes in gets handled in another class and gets
'passed to this class through the method called 'orderIsWorking', which
'can be seen at the bottom. This method queues the relevant information
Any help on the above problem would be greatly appreciated
I am creating a basic stock trading platform. My app has to deal with 1000s of incoming messages and for each message process and then update various windows (with price and qty etc). I have all the basic logic behind the app working, but I would like to improve the performance.
I understand that Threads along with Queues can be used to enhance my apps speed. But when I tried to implement both of these techniques it only seemed to slow things down even more. Please see below for a snippet of code from my app:
'Firstly I declare two queues
'Then I start two while loops on seperate threads, which will be used to
'remove items from each queue
'Each message that comes in gets handled in another class and gets
'passed to this class through the method called 'orderIsWorking', which
'can be seen at the bottom. This method queues the relevant information
VB.NET:
Private mWatchQ As New Queue 'declare marketWatch queue
Private wOrdersWEnQ As New Queue 'declare working orders queue
Private Sub initiateThreads() 'start threads
Dim mWatchT As New Thread(AddressOf mWatchLoop)
Dim wOrdersEnT As New Thread(AddressOf wOrdersEnLoop)
mWatchT.IsBackground = True
wOrdersEnT.IsBackground = True
mWatchT.Start()
wOrdersEnT.Start()
End Sub
Private Sub mWatchLoop()
While True
If mWatchQ.Count > 0 Then
Dim orderDetails = mWatchQ.Dequeue()
SyncLock mWatch
mWatch.orderID = orderDetails(0)
mWatch.ticker = orderDetails(1)
mWatch.isBid = orderDetails(2)
mWatch.addStock = True
mWatch.findRow()
End SyncLock
End If
End While
End Sub
Private Sub wOrdersEnLoop()
While True
If wOrdersWEnQ.Count > 0 Then
Dim orderDetails2 = wOrdersWEnQ.Dequeue()
SyncLock wOrdersW
wOrdersW.tempBS = orderDetails2(0)
wOrdersW.tempPrice = orderDetails2(1)
wOrdersW.tempQty = orderDetails2(2)
wOrdersW.orderIDTemp = orderDetails2(3)
wOrdersW.updateStatus()
End SyncLock
End If
End While
End Sub
Public Sub orderIsWorking(ByVal isInitialOrder As Boolean, ByVal orderID As String, ByVal ticker As String, _
ByVal country As String, ByVal sector As String, ByVal isBid As Boolean, ByVal price As String, _
ByVal qty As String)
Dim BorS As Char
If isBid Then
BorS = "B"
Else
BorS = "S"
End If
If isInitialOrder Then
Dim orderDetailsMW() = {orderID, ticker, isBid}
SyncLock mWatchQ
mWatchQ.Enqueue(orderDetailsMW)
End SyncLock
Dim orderDetailsWoW() = {BorS, price, qty, orderID}
SyncLock wOrdersWEnQ
wOrdersWEnQ.Enqueue(orderDetailsWoW)
End SyncLock
End Sub
Any help on the above problem would be greatly appreciated
Last edited by a moderator: