KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
191 stars 49 forks source link

pyq doesn't run faster parallelly #129

Closed fouvy closed 4 years ago

fouvy commented 4 years ago

Questions

Steps to reproduce the issue

Expected result

Actual result

Workaround

pyq doesn't run faster parallelly with kdb+ 4.0. This is my testbench.py file

import numpy as np
from time import time

def testbench(n):
    A = np.random.random((1, n))
    # Matrix multiplication
    N = 800000
    t = time()
    for i in range(N):
        A = A*A
    delta = time() - t
    print('Dotted two %dx%d matrices in %0.2f s.' % (1, n, delta))
    return np.sum(A)

if __name__ == "__main__":
    print(testbench(40000))

Then I ran with my kdb+ like following:

q -s 8
q)\l p.q
q)p)from testbench import testbench
q)l:40000 40000 40000 40000 40000 40000 40000 40000 
q)testbench:.p.get[`testbench;<]
q)testbench peach l
Dotted two 1x40000 matrices in 35.76 s.
Dotted two 1x40000 matrices in 35.76 s.
Dotted two 1x40000 matrices in 35.81 s.
Dotted two 1x40000 matrices in 35.80 s.
Dotted two 1x40000 matrices in 35.82 s.
Dotted two 1x40000 matrices in 35.82 s.
Dotted two 1x40000 matrices in 35.83 s.
Dotted two 1x40000 matrices in 35.85 s.
0 0 0 0 0 0 0 0f
q)testbench[l 0]
Dotted two 1x40000 matrices in 10.61 s.
0f
q)\s
8i

I found that pyq cannot run faster when I testing code under kdb+ 4.0. I can run my code faster when I run peach with c library. I thought it might be kdb+ slave doesn't fork embedpy independently.

cmccarthy1 commented 4 years ago

Hi @fouvy

The updated peach functionality introduced in kdb+ 4.0 relates to updated performance for kdb+ primitives only, this is explicitly outlined here

As such it would not be expected that the addition of distributed primitives in kdb+ 4.0 would have any impact on the speed of execution of any code on Python side as is the case in your example. These are two separate problems.

github-actions[bot] commented 4 years ago

Stale issue message