Skip to content
This repository has been archived by the owner on Jun 20, 2019. It is now read-only.

Performance issues #1

Closed
jonmunm opened this issue Dec 19, 2016 · 10 comments
Closed

Performance issues #1

jonmunm opened this issue Dec 19, 2016 · 10 comments
Assignees

Comments

@jonmunm
Copy link

jonmunm commented Dec 19, 2016

First of all, thanks. I take your option changing de repo since the previous gave many errors.
Some points:

  1. You say put the config 'public_key' => 'app\storage\PublicKeyStorage', but the class is namespaced with namespace app\security\storage;

Here the thing. I've been doing some performance debug with Google Chrome and noted that token issuance take some long time (compare with other implementations I've made with .NET)

After perform many request at the token endpoint, the minimun take 1.86s and the maximun 2.3s (in .NET this take 200ms aprox).

Then, when I tried to access a protected resource in my api, this also take a long time. My resource endpoint doesn't perform query operations (to discard this variable) in order to isolate the token verification process time.

The time of this was: maximun -> 2.5s, minimun 1.8s

I'll be thankfull if you can light me in the right direction to get better performance. My server is an Ububntu Server. Perphabs if I change the storage modes like pointed in http://bshaffer.github.io/oauth2-server-php-docs/storage/multiple/

I would like a scheman like this:

  1. Users -> PG Database (I have many users)
  2. Scopes, clients -> Memory (I have few scopes and clients)
  3. Tokens -> Memory or other storage no being PG Database. (I couldn't figured out where .NET stored tokens, but it wasn't the MS Server instance used by that api)

Best regards

Jona

@mtangoo
Copy link
Contributor

mtangoo commented Dec 19, 2016

Hi,

First of all, thanks. I take your option changing de repo since the previous gave many errors.

Welcome! I had to develop this fork as original repo had a lot of confusions that I though need to be fixed.

I'll be thankfull if you can light me in the right direction to get better performance. My server is an Ububntu Server. Perphabs if I change the storage modes like pointed in http://bshaffer.github.io/oauth2-server-php-docs/storage/multiple/

I would suggest few tests to find out the bottleneck:

  • Check the difference with normal token vs JWT token. If the time difference is significant then the source is JWT generation. If not then the base library is the issue and I would open a bug report to bshaffer repo. Else Proceed with next stage

  • I will try to use database to store Private/Public keys and use Yii's DAO to fetch them. If it improves the the problem is reading of file every time the program reads the key. If changing storage does not improve anything, proceed to next stage

  • I will try to change the library options for generating JWT. Try changing to HS256

Let me know of the results for further ideas.
Cheers!

@jonmunm
Copy link
Author

jonmunm commented Dec 19, 2016

Hi

Check the difference with normal token vs JWT token. If the time difference is significant then the source is JWT generation. If not then the base library is the issue and I would open a bug report to bshaffer repo. Else Proceed with next stage

Tested, similar time response

I will try to use database to store Private/Public keys and use Yii's DAO to fetch them. If it improves the the problem is reading of file every time the program reads the key. If changing storage does not improve anything, proceed to next stage

I'll do it, assumig that file_get_content is slower that DB access. Another testt would be put the keys's string in the class

I will try to change the library options for generating JWT. Try changing to HS256

I'll tested.

What about the storage modes I mentioned earlier??

I'll tell you my results.

Thanks

@mtangoo
Copy link
Contributor

mtangoo commented Dec 19, 2016

Tested, similar time response related configurations?

Did you remove all JWT configurations?

What about the storage modes I mentioned earlier??

I don't think they will be of any value. I might be wrong though. My suspects are JWT specific parts

@jonmunm
Copy link
Author

jonmunm commented Dec 20, 2016

I managed to improve time responses taking theses steps:

  1. Reading the private and public key from the class (string hard-coded). This way, I figured out that file_get_contents was taking some time to get de files

  2. Disable all loggin and debug features.

Yet, the token issuance take 800ms aprox, and resource request 500ms to 700ms aprox. By experience, this should be faster to feed a SPA client.

Changing to HS256 didn't make any inprovements

I have now JWT issuance, but I have one question (besides the obvious one, that is, how to improve performance even more) ...... where JWT are stored?? They are not in DB.

Best regards.

@mtangoo
Copy link
Contributor

mtangoo commented Dec 21, 2016

where JWT are stored?? They are not in DB.

Why would you store JWT on database? They are self contained A
and storing them will be redundant, costly and unnecessary complexity. Is there something specific you need?

@mtangoo
Copy link
Contributor

mtangoo commented Dec 21, 2016

Also what other libraries that offer same functionalities measure up other than mentioned .Net in terms of latency?

@mtangoo
Copy link
Contributor

mtangoo commented Dec 21, 2016

As a favor can you help document what you have done exactly on the Wiki to help others who would face same issue?

Even a comment here should be enough!

@jonmunm
Copy link
Author

jonmunm commented Dec 21, 2016

Why would you store JWT on database? They are self contained A
and storing them will be redundant, costly and unnecessary complexity. Is there something specific you need?

My mistake. Wrong question, I forgot the self-contained feature of JWT ... I was thnking wrong, it was too late in night after all

Also what other libraries that offer same functionalities measure up other than mentioned .Net in terms of latency?

Identity Server 3

As a favor can you help document what you have done exactly on the Wiki to help others who would face same issue?

Even a comment here should be enough!

I'll be glad, after the help you gave me. Please tell what specific knowledge you want me to share.

One question. ¿Does the library have a feature to extract token claims?

@mtangoo mtangoo self-assigned this Dec 21, 2016
@mtangoo
Copy link
Contributor

mtangoo commented Dec 21, 2016

@jonmunm you can extract it in two ways

  1. You can use (already installed dependency) to this library JWT to decode the token in JWT terminologies. Here is a working example:
    public static function findIdentityByAccessToken($token, $type = null)
    { 
        $pubKeyStorage = Yii::$container->get('public_key');
        $algo = $pubKeyStorage->getEncryptionAlgorithm();
        $pubKey = $pubKeyStorage->getPublicKey();
        
        $decoded = \Firebase\JWT\JWT::decode($token, $pubKey,[$algo]);
        echo json_encode(['token'=>$decoded]); die();
        //return null;
    }
  1. Directly decode using the library ready method that does heavy lifting for you:
    public static function findIdentityByAccessToken($token, $type = null)
    { 
        $accessToken = Yii::$container->get('access_token');  
        echo json_encode(['token'=>$accessToken->getAccessToken($token)]); die();
        //return null;
    }

So choice is yours

@mtangoo
Copy link
Contributor

mtangoo commented Dec 21, 2016

I'll be glad, after the help you gave me. Please tell what specific knowledge you want me to share.

Users of the library are likely to hit the performance issue that you found yourself in. Refer your comment here:

Disable all loggin and debug features.

Here is where I need to know exactly which logging and debug features you disabled

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants